我有一个System.Windows.Forms.DataGridView
其中一列只有组合框。当 ComboBox 发生变化时,我需要知道新项目是什么,以及发生事件的 ComboBox 的行索引。后者给我带来了麻烦。我有以下内容:
class MyForm : Form
{
private System.Windows.Forms.DataGridView m_GridView;
private System.Windows.Forms.DataGridViewComboBoxColumn m_ComboBoxColumn;
public MyForm ()
{
/* ... lots of initialisation stuf...*/
this.m_GridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.m_ComboBoxColumn});
}
private void m_GridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox comboBox = e.Control as ComboBox;
if (comboBox != null)
{
comboBox.SelectedIndexChanged -= new EventHandler(m_ComboBoxColumn_SelectedIndexChanged);
comboBox.SelectedIndexChanged += new EventHandler(m_ComboBoxColumn_SelectedIndexChanged);
}
}
private void m_ComboBoxColumn_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox comboBox = (ComboBox) sender;
string item = comboBox.Text;
if (item != null)
{
System.Diagnostics.Debug.WriteLine(item); // This is the new item text
// Now I need the row index of this ComboBox in 'm_GridView' (or 'm_ComboBoxColumn')
}
}
}
如何DataGridViewComboBoxColumn
在最后一种方法中找到 ComboBox 的行索引?