简体   繁体   English

当我选择 combobox1 最后一个值时,combobox2 最后一个值将被自动选择

[英]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) .SelectionChanged的事件ComboBox1 ,所设定SelectedIndexComboBox2(项目在数量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;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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