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 下拉列表框设置选择事件
最新推荐文章于 2024-08-21 10:21:00 发布