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

How to link list boxes

Status
Not open for further replies.

hugh999

MIS
Nov 29, 2001
129
IE
Can someone please point me to site on how to link list boxes or show me some sample code on how to achieve the following:

If a user selects / highlights the first item in listbox1, then the first item in listbox2 will also get selected / highlighted.

Thanks
 

How about - place ListBox1 and ListBox2 on the Form:
Code:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
                           ByVal e As System.EventArgs) _
                           Handles MyBase.Load
        For i As Integer = 0 To 25
            ListBox1.Items.Add("Item " & i)
            ListBox2.Items.Add("Item " & i)
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
                                              ByVal e As System.EventArgs) _
                                              Handles ListBox1.SelectedIndexChanged
        ListBox2.SelectedItem = ListBox1.SelectedItem
    End Sub

    Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, _
                                              ByVal e As System.EventArgs) _
                                              Handles ListBox2.SelectedIndexChanged
        ListBox1.SelectedItem = ListBox2.SelectedItem
    End Sub
End Class

Have fun.

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

Part and Inventory Search

Sponsor

Back
Top