Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox set as SelectionMode Multiple only setting one item

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have a listboxes that are set as SelectionMode="Multiple".

I am trying set them programmatically. I have a comma delimited string that I split into an array then set each item. The problem is that no matter how many I set, only the last one stays selected.

Code:
Dim listBoxValues As String()

'set the string as comma delimited

 listBoxValues = Split(controlValue, ",")
 For Each value As String In listBoxValues
       DirectCast(item, ListBox).SelectedValue = value
 Next

Why is only the last one getting set?

Thanks,

Tom
 

ListBox1 with its SelectionMode set to MultiSimple

Code:
Dim controlValue As String = "One.Two,Three,Four"
Dim listBoxValues() As String = Split(controlValue, ",")
Dim indx As Integer = 0

ListBox1.Items.Clear()

For Each value As String In listBoxValues
    ListBox1.Items.Add(value)
    ListBox1.SelectedIndex = indx
    indx += 1
Next
I am sure there is a better way...

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top