|
-
Jun 13th, 2003, 08:59 AM
#1
Thread Starter
Member
Selected item index on a listbox...
Hi every1 !
I have a listbox and an array.
I want to link every listbox item to an array value, so, when I double click an item I want to retrieve its Index ( 1,2,3.....) like on VB6... but
listbox.selecteditem returns the string, not the position...
I cant find a command lie .item.index....
help ?
Thanks !!
-
Jun 13th, 2003, 09:12 AM
#2
Sleep mode
Re: Selected item index on a listbox...
Is this what you want ?
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arry() As String = {"item1", "item2", "item3"}
'bind the array to the listbox
ListBox1.Items.AddRange(arry)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'show the index of selected item
MessageBox.Show(ListBox1.SelectedIndex)
End Sub
End Class
-
Jun 13th, 2003, 02:42 PM
#3
Thread Starter
Member
I really dont know...
selecteditems is returning -1 ....
I can add items using:
listbox.items.add "string"
and when I double click an item it fires doubleclick event where i put the msgbox with ....selecteditem.
showing -1.
that is my doubt...
Thanks !!
-
Jun 13th, 2003, 02:58 PM
#4
Sleep mode
I can't understand what problem you are in now . I've tried it here and worked fine . You might need to try
VB Code:
Listbox1.SelectedItem.ToString()
-
Jun 13th, 2003, 03:05 PM
#5
Thread Starter
Member
still...
ok...
SelectedItem.ToString() is returning me the text item, not the "position" of the item I have selected....
Does that help ?
Do you remember in VB6 that I could retrieve the index of an item, for example if I click the 4th item on the list, itemindex would return 4. not the text.
-
Jun 13th, 2003, 04:53 PM
#6
Sleep mode
What about the first code I posted . It does what you want I guess . Like this :
VB Code:
MessageBox.Show(ListBox1.[B]SelectedIndex[/B] )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|