peanut1010
asked on
vb.net read multiple selection is listbox
I have a listbox that allows the user to make multiple selections. How can I loop through just the selections and display in a msgbox
ASKER
yes please
there ya go in your event that you want to see the selected items you can do it this way.
Dim oItem As Object
Dim s As String
For Each oItem In ListBox1.SelectedItems
s &= CType(oItem, String) & vbCrLf
Next
MsgBox("Results: " & vbcrlf & vbcrlf & s)
Dim oItem As Object
Dim s As String
For Each oItem In ListBox1.SelectedItems
s &= CType(oItem, String) & vbCrLf
Next
MsgBox("Results: " & vbcrlf & vbcrlf & s)
ASKER
ok, thanks
I also have been trying to make it compare the text to what is hardcoded
example
in my listbox1 I have
Dog
Cat
Bird
I am trying to have a code that only does something when the current selection is Cat
I was tryingto do
if listbox1.items.item(o) = "Cat"
but nothing I also tried
if listbox1.selecteditem("Cat ") = "Cat"
but it does work right
I need something that will only work if the current selection is hit
in vb6
I used
if listbox.text = "Cat" then
and it worked
any ideas of what to do
I also have been trying to make it compare the text to what is hardcoded
example
in my listbox1 I have
Dog
Cat
Bird
I am trying to have a code that only does something when the current selection is Cat
I was tryingto do
if listbox1.items.item(o) = "Cat"
but nothing I also tried
if listbox1.selecteditem("Cat
but it does work right
I need something that will only work if the current selection is hit
in vb6
I used
if listbox.text = "Cat" then
and it worked
any ideas of what to do
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ListBox1.SelectedItems collection
do ya need some code on how to go throught a collection?