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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox.setSelected where value matches array

Status
Not open for further replies.

DannyTmoov2

IS-IT--Management
Jan 7, 2003
49
0
0
GB
I have an array of values that match some of the values (as in valueMember not displayMember) within a multi-select listbox bound to a datatable.

I want to select all the items in my listbox where the value is in my array.

I can't seem to figure out the right syntax.

I currently have

Code:
Dim index As Integer
For n = 0 To UBound(arrMachineStatus)
            index = ListBox1.Items.IndexOf(arrMachineStatus(n)) 
            If index > -1 Then
                ListBox1.SetSelected(index, True)
            End If
        Next n

but index is always returning as -1

any help much appreciated
 
Try this:

Dim index As Integer
For n = 0 To UBound(arrMachineStatus)
index = ListBox1.Items.IndexOf(arrMachineStatus(n))
If index > -1 Then
ListBox1.SelectedValue(ArrayValue)
End If
Next n
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top