AznDevil92 AznDevil92 - 1 year ago 356 Question

Set Combobox Value base on another Combobox Selected Value - VB.NET

I have two comboboxes. If the user selects a certain value from the first combobox then I want the second combobox to automatically change and select to its corresponding value.

For example:

If Me.InstitutionAdvisoryFirmsComboBox1.SelectedValue = 3 Then
Me.WeightComboBox1.SelectedValue = 2

I have also tried:

If Me.InstitutionAdvisoryFirmsComboBox1.SelectedText = "Internal Guidelines" Then
Me.WeightComboBox1.SelectedText = "None"

Can anyone help?

Answer Source
//selected index changed event for the combo box 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles InstitutionAdvisoryFirmsComboBox1.SelectedIndexChanged

    If Me.InstitutionAdvisoryFirmsComboBox1.SelectedIndex = 3 Then 
        If Me.WeightComboBox1.Items.Count >= 2 Then // make sure you are not accessing an index out of range
            Me.WeightComboBox1.SelectedIndex = 2
        End If
    End If

End Sub 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download