用户如何知道ComboBox中的选项是否被更改?

3
问题在于当用户进行更改并且应用程序代码设置SelectedItem时,SelectedIndexChanged事件会被调用两次。
有没有办法判断项目是通过鼠标或键盘的直接操作更改的?

这个问题可能会有所帮助 https://dev59.com/FnA75IYBdhLWcg3wf5NV - 26071986
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();
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接