如何将DataGridViewComboBoxColumn绑定到OnChange事件(C#) [英] How to bind DataGridViewComboBoxColumn to a OnChange event (C#)
问题描述
我有一个标准的 DataGridView
,而我的最后一列是一个 DataGridViewComboBoxColumn
。
我想添加一个事件,以便当该列中任何行的选定索引发生更改时,会触发一个事件,并将该数据保存到db。
I have a standard DataGridView
, and my last column is a DataGridViewComboBoxColumn
.
I would like to add an event so that when the selected index of any of the rows in that column changes, an event is triggered and I save that data to db.
我正在努力一个小时左右,找不到任何会触发这个事件的事件。
I'm struggling with this for an hour or so and couldn't find any event that would trigger this...
任何帮助将不胜感激! !!
Any help would be appreciated!!!
推荐答案
在$ $ c $的 EditingControlShowing
c> DataGridView 将方法附加到组合框 SelectedIndexChanged
事件。
In the EditingControlShowing
event of the DataGridView
attach a method to the combobox SelectedIndexChanged
event.
例如:
private void DGV_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (DGV.CurrentCell.ColumnIndex == comboColumnIndex && e.Control is ComboBox)
{
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged;
}
}
现在以下方法可以做任何你想要的:
Now in the below method you can do whatever you want:
private void LastColumnComboSelectionChanged(object sender, EventArgs e)
{
// Do saving work here
}
这篇关于如何将DataGridViewComboBoxColumn绑定到OnChange事件(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!