我在 DataGridViewComboBoxCell 中有一个项目列表;我想在用户单击一个值后立即做某事。
事件是什么,或者我怎么能做我想做的事?
当我们离开单元格时调用 CellValueChanged...
我在 DataGridViewComboBoxCell 中有一个项目列表;我想在用户单击一个值后立即做某事。
事件是什么,或者我怎么能做我想做的事?
当我们离开单元格时调用 CellValueChanged...
您可以处理组合框的 selectededindexchanged 。
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
// first remove event handler to keep from attaching multiple:
cb.SelectedIndexChanged -= new
EventHandler(cb_SelectedIndexChanged);
// now attach the event handler
cb.SelectedIndexChanged += new
EventHandler(cb_SelectedIndexChanged);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected index changed");
}
另一种可能的方法是:
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb == null)
return;
dataGridView1.EditingControlShowing -= dataGridView1_EditingControlShowing;
cb.SelectedIndexChanged += cb_SelectedIndexChanged;
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected index changed");
}
你只做一次。