shows how to select items in a ListBox in code

Started by nandagopal, May 20, 2009, 07:10 PM

Previous topic - Next topic

nandagopal

For a ListBox that allows single selection, either set the SelectedIndex or the SelectedItem property.

For a ListBox that allows multiple selection, use the SetSelected method to selected or deselect items.


' Select item 4 in ListBox1.
' (Alternatively set ListBox1.SelectedItem.)
ListBox1.SelectedIndex = 4
'Or do this: ListBox1.SelectedItem = ListBox1.Items(4)

' Select every third item in ListBox2.
For i As Integer = 1 To ListBox2.Items.Count - 1 Step 3
    ListBox2.SetSelected(i, True)
Next i



dhoni

this code is very useful to me for select item in listbox code
it can easily use in vb.net code