使用mysql我用选择的combobox1提供combobox2。它工作正常。但问题是第一个选择似乎没有触发事件处理程序。我第二次这样做会触发它。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.SelectedValueChanged += new EventHandler(comboBox1_selectedvaluechanged);
}
private void comboBox1_selectedvaluechanged(object sender, EventArgs e)
{
region = comboBox1.SelectedItem.ToString();
values_to_venue();
db.connection.Close();
}
答案 0 :(得分:2)
这是因为在组合框的SelectedIndex更改之前,您不会创建事件处理程序。这与SelectedValue更改一起触发。在load方法中创建事件处理程序,确保在第一个SelectedValue更改时它存在。如果你把它放在Load中,请确保在卸载时用 - =清理它。或者,您可以在构造函数中创建它,然后您就不需要将其删除。
答案 1 :(得分:0)
您确实想在构造函数或加载方法中设置事件;另外,我认为您要使用的事件是ComboBox.SelectionChangeCommitted,因为如果用户使用键盘上的向上/向下箭头导航DropDown列表,SelectedIndexChanged将在提交选择之前触发 - 这就是您想要的???? ??