简体   繁体   中英

When i select the combobox1 last value the combobox2 last value will be automatically selected

我有2个组合框我想要实现这样的事情,当我选择combobox1最后一个combobox2最后一个将被自动选中,我怎样才能做到这一点使用C#代码,请帮帮我,

In the SelectionChanged event of ComboBox1 , set the SelectedIndex of ComboBox2 to (the number of items in ComboBox2 ) - 1) . This code should work:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    ComboBox2.SelectedIndex = ComboBox2.Items.Count - 1
End Sub

The Bellow Code Work Fine For Me anyway thanks to all for your replays... :)

  private void combobox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (combobox1.SelectedIndex == (combobox1.Items.Count - 1))
        {
            combobox2.SelectedIndex = combobox2.Items.Count - 1;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM