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