Search code examples
c#sqlvb.netcomboboxselecteditem

How to make a combobox.text change with a scroll on another comobox in "real time"?


I'm trying to make a combobox.text change in real time when I'm wheeling on another combobox.

Here is the code :

Private Sub ComboBox2_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBoxNomUnités.SelectionChangeCommitted
        Try
            ComboBox1.Text = GetStringFromQuery("SELECT qualité_unité FROM liste1 Where Nom_Unité = '" & ComboBox2.Text & "'")
        Catch ex As Exception
        End Try

    End Sub

Problem is : Combobox2.text is always equal to the "previous" data, not the actual one corresponding to Combobox1.text.

Example of the problem here In this little mp4, you can see that the "Unit Quality" is always "late" vs the "Unit Names".

On another topic, a dev told me to use Combobox.selecteditem.tostring instead of Combobox.text but it's not working here...


Solution

  • The problem you are facing occurs because you are using the SelectionChangeCommitted event. What you need is the SelectedIndexChanged event.

    In the first line, try replacing Handles ComboBoxNomUnités.SelectionChangeCommitted with Handles ComboBoxNomUnités.SelectedIndexChanged and give it a go.