如何知道USER是否更改了ComboBox中的Selected Item?

时间:2012-08-03 14:18:35

标签: .net winforms combobox

问题是当用户进行更改时以及应用程序代码设置SelectedItem进行更改时,都会调用SelectedIndexChanged事件。

有没有办法通过用户从鼠标或键盘直接操作来判断项目是否已更改?

1 个答案:

答案 0 :(得分:1)

尝试类似SelectedChangeCommitted MSDN

的内容
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{

    ComboBox comboBox = (ComboBox) sender;

    // Change the length of the text box depending on what the user has 
    // selected and committed using the SelectionLength property.
    if (comboBox.SelectionLength > 0)
    {
        textbox1.Width = 
            comboBox.SelectedItem.ToString().Length *
            ((int) this.textbox1.Font.SizeInPoints);
        textbox1.Text = comboBox.SelectedItem.ToString();
    }
}