3

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

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

4

1 回答 1

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();
    }
}
于 2012-08-03T14:41:35.827 回答