如何获取网格视图的列索引

时间:2014-03-22 03:49:04

标签: c# datagridview

我想在DataGridView事件中获得CellEndEdit的列索引。

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    int columnIndex = dataGridViewMsg.Columns[e.ColumnIndex].ToString();
}

1 个答案:

答案 0 :(得分:1)

你几乎就在那里:

只做

private void dataGridView1_CennEndEdit(object sender, DataGridViewCellEventArgs e)
{
    int columnIndex = e.ColumnIndex;
}

这将为您提供当前正在编辑的单元格的列索引。

虽然您可能只想使用e.ColumnIndex来做任何想要做的事情来节省创建新变量的开销。从你的问题中不清楚最终目标是什么。

相关问题