Join
the community
Sign-up
Ask a question »

Visual Basic - Listbox issue

May 2013


[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.

Published by aakai1056
This document entitled « Visual Basic - Listbox issue » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.
Receive our newsletter

health.kioskea.net

MySQL - Htaccess redirection issue
Convert Hex to ASCII