且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将DataGridViewComboBoxColumn绑定到OnChange事件(C#)

更新时间:2022-05-25 02:43:05

在$ $ 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
}