ComboBox SelectedIndexChanged event: how to get the previously selected index?

前端 未结 6 1082
闹比i
闹比i 2021-01-17 11:35

I have a user control which has a ComboBox and a SelectedIndexChanged event handler. In the event handler, I need to be able to tell what was the previously selected index.

6条回答
  •  无人共我
    2021-01-17 11:55

    how about the comboBox_SelectionChangeCommitted event? this is called after the selection is made, the menu is collapsed but the item is not compleetly changed. So just read comboBox.SelectedText or comboBox.SelectedValue and even comboBox.SelectedIndex

    private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
    {
        int prevIndex = comboBox1.SelectedIndex;
    }
    

提交回复
热议问题