Click here to Skip to main content
15,314,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all, I have a question, how can I make during a selectedindexchanged of a combobox make the other one the same index? Because I have to make sure that when selected a index it became the same (not value but index). I was thinking of an if statement but for all the index is a bit non optimal, is there any way to do this? Thanks in advice

What I have tried:

BASIC
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

        If ComboBox1.SelectedIndex = (0) Then
            ComboBox2.SelectedIndex = (0)
        End If
        If ComboBox1.SelectedIndex = (1) Then
            ComboBox2.SelectedIndex = (1)
        End If
        If ComboBox1.SelectedIndex = (2) Then
            ComboBox2.SelectedIndex = (2)
        End If
    End Sub
Posted
Updated 28-Dec-21 18:15pm

I found out a solution that seem working it's this, if anyone needed or may give some help. Thanks anyways
BASIC
rivate Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        For i = 0 To ComboBox1.Items.Count
            If ComboBox1.SelectedIndex = (i) Then
                ComboBox2.SelectedIndex = (i)
            End If
        Next
    End Sub
   
v3
How about
ComboBox2.SelectedIndex = ComboBox1.SelectedIndex
instead of your for loop?
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900