private void DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (StoreSwap_Tab_DataGridView.CurrentCell != null && e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
{
//创建下拉列表框改变事件
(e.Control as ComboBox).SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
//创建下拉列表框离开焦点事件 添加该事件是为了删除动态事件 以免多次调用
(e.Control as ComboBox).Leave += new EventHandler(ComboBox_Leave);
}
}
//离开焦点事件
private void ComboBox_Leave(object sender, EventArgs e)
{
//删除动态调用
(sender as ComboBox).SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
(sender as ComboBox).Leave -= new EventHandler(ComboBox_Leave);
}
//下拉列表框改变事件
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
} C# DataGridView 中 DataGridViewComboBoxCell 下拉列表框设置选择事件
DataGridView下拉列表事件处理
最新推荐文章于 2024-07-05 15:32:58 发布
本文介绍了一个关于DataGridView中使用ComboBox进行编辑时如何添加和移除事件处理程序的方法。通过在DataGridViewEditingControlShowing事件中为DataGridViewComboBoxEditingControl绑定SelectedIndexChanged和Leave事件,实现了对下拉列表框的选择更改和焦点离开的响应。
7629

被折叠的 条评论
为什么被折叠?



