make the item in list box auto select

yaniv

Well-known member
Joined
Apr 15, 2002
Messages
162
Location
israel
when you create a list box and the user paging throw the items, the listbox.text always gives the same (the first) value.
The user has to "select" the item, "paint" it in blue- to get the item in the text.

Can you make the item in the listbox "autoselect", wich mean that the user dont has to touch the listbox again?

I found the "reselecting" very uneasy way (the user will usually click another button to make the form send the value to database or so).
 
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.SelectedItem = ListBox1.Items.Item(1)
        /// put your chosen item where it says 1
        MsgBox(ListBox1.SelectedItem)
    End Sub
 
but, this way i allways get the first item, can i set the selected item to be the one that the listbox currently show?
 
yes , the 1 that the listbox is currently showing is the SelectedIndex
this returns the item thats currently selected :
Code:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If ListBox1.SelectedIndex < 0 Then Exit Sub
        ListBox1.SelectedItem = ListBox1.Items.Item(ListBox1.SelectedIndex)
        /// put your chosen item where it says 1
        MsgBox(ListBox1.SelectedItem)
    End Sub
 
Back
Top