locked
listbox multiselect RRS feed

  • Question

  • what event should i use

    i have listbox and the selectionmode properties i change to multiextended

    i try this code

    Private Sub LstUnit_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LstUnit.SelectedIndexChanged

    Dim i As Integer

    Sql = "delete from filter where sort=1"

    Cmd = New OleDbCommand(Sql, Conn)

    Cmd.ExecuteNonQuery()

    Dim text_item As String

    If syarat_filter = True Then

    'Sql = "drop view Q_Filter_ON "

    'Cmd = New OleDbCommand(Sql, Conn)

    'Cmd.ExecuteNonQuery()

    End If

    end sub

     

    this event have a problem

    because i can't use CTRL + click to select the item

     

    if i don't use those event, i can use CTRL + Click to seleck the item

     

    please help me

    Friday, April 20, 2007 7:17 AM

Answers

  • AuliyaIkhsan,

     

    The big thing to remember is that listboxes SelectedItems are cast as System.Object because each of the types of datasources you can bind to them have different forms, so you must cast them (using CType()) to the correct form.

     

    Code Snippet

     

    Dim oRow As System.Data.Common.DbDataRecord

     

    For i = 0 To lstAuthors.SelectedItems.Count - 1

    ' Get the DbDataRecord of the selected item

       oRow = CType(lstAuthors.SelectedItems(i) , System.Data.Common.DbDataRecord)

    ' Get the contents of the field that holds the selected value

       iT = CInt(oRow(lstAuthors.ValueMember))

       tta.InsertQuery(i1, iT)

     

    Next

     

    Please read the following thread that can help you to this problem:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=117775&SiteId=1

     

     

    Friday, April 27, 2007 8:16 AM
  • i maybe have a better answer?

     


      

    Code Snippet

    Private Sub LstUnit_KeyUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles LstUnit.KeyUp


            Call Unit()


    End Sub

     

        Private Sub LstUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstUnit.SelectedIndexChanged
            If ModifierKeys = Keys.Control Or ModifierKeys = Keys.Shift Then
            Else
                Call Unit()


    End If

     

    Private Sub Unit()

     

    'your code

     

    end sub

     

    with all of this event handler, both you can use CTRL, Shift, or just click the list box

     

    Thursday, May 3, 2007 1:14 AM

All replies

  • AuliyaIkhsan,

     

    The big thing to remember is that listboxes SelectedItems are cast as System.Object because each of the types of datasources you can bind to them have different forms, so you must cast them (using CType()) to the correct form.

     

    Code Snippet

     

    Dim oRow As System.Data.Common.DbDataRecord

     

    For i = 0 To lstAuthors.SelectedItems.Count - 1

    ' Get the DbDataRecord of the selected item

       oRow = CType(lstAuthors.SelectedItems(i) , System.Data.Common.DbDataRecord)

    ' Get the contents of the field that holds the selected value

       iT = CInt(oRow(lstAuthors.ValueMember))

       tta.InsertQuery(i1, iT)

     

    Next

     

    Please read the following thread that can help you to this problem:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=117775&SiteId=1

     

     

    Friday, April 27, 2007 8:16 AM
  • i maybe have a better answer?

     


      

    Code Snippet

    Private Sub LstUnit_KeyUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles LstUnit.KeyUp


            Call Unit()


    End Sub

     

        Private Sub LstUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstUnit.SelectedIndexChanged
            If ModifierKeys = Keys.Control Or ModifierKeys = Keys.Shift Then
            Else
                Call Unit()


    End If

     

    Private Sub Unit()

     

    'your code

     

    end sub

     

    with all of this event handler, both you can use CTRL, Shift, or just click the list box

     

    Thursday, May 3, 2007 1:14 AM