Get the current index of a ComboBox?

后端 未结 3 454
心在旅途
心在旅途 2021-01-06 08:36

Say I had a ComboBox with these values:

Black
Red
Blue

And I have Red currently selected. If the user then hits backspace and

3条回答
  •  天涯浪人
    2021-01-06 09:01

    The way you are doing is fine. You have to keep the selected index in memory because it returns -1 as the SelectedIndex when the text is deleted. You could take the index in this way too.

    private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        currentMyComboBoxIndex = myComboBox.SelectedIndex;
    }
    

提交回复
热议问题