[Visual Basic] Listbox issue
Issue
I am creating a form to add data into a table with VB5 and included a listbox where you select an item from the list.
When testing the page, if the user has not clicked in the listbox, no list item is selected.
How to get:
- the first item in the list selected by default
- if the user selects another item then his choice is taken into account ..
Solution
Your code must look like this:
Private Sub CmdPrecedent_Click()
Dim i As Integer
i = List1.ListIndex
If i > 0 Then
i = i - 1
List1.ListIndex = i
Label1 = List1.List(i)
End If
End Sub
Private Sub CmdSuivant_Click()
Dim i As Integer
i = List1.ListIndex
If i < List1.ListCount - 1 Then
i = i + 1
List1.ListIndex = i
Label1 = List1.List(i)
End If
End Sub
Solved by
Savoye
See also
Knowledge communities.