[RESOLVED] How to choose a ListBox itemdata other than zero???
I am writing some code, that must be able to choose a listbox item, other than zero. If it selects a listbox itemdata zero, then nothing happens. But if the user was to click on a item in that listbox, then it comes up with a messagebox saying congratulations and then ends the program.
Thanks in advance!!
Re: How to choose a ListBox itemdata other than zero???
Code:
Option Explicit
Private Sub Form_Load()
'~~~ Loading sample datas
List1.AddItem "Contains 1"
List1.ItemData(List1.NewIndex) = 1
List1.AddItem "Contains 2"
List1.ItemData(List1.NewIndex) = 2
List1.AddItem "Contains 0"
List1.ItemData(List1.NewIndex) = 0
List1.AddItem "Contains 4"
List1.ItemData(List1.NewIndex) = 4
List1.AddItem "Contains 0"
List1.ItemData(List1.NewIndex) = 0
End Sub
Private Sub List1_Click()
If List1.ItemData(List1.ListIndex) <> 0 Then '~~~ Check if the ItemData of selected item is not 0
MsgBox "Congratulations !" '~~~ If so, display the message
Unload Me '~~~ Close the form
End If
End Sub
...:wave:
Re: How to choose a ListBox itemdata other than zero???
I will try it!!
And thanks for the source code, my friend!!