[英]How can I get Column index of grid view
I would like to get column index of a DataGridView
inside the CellEndEdit
event. 我想在CellEndEdit
事件中获取DataGridView
列索引。
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int columnIndex = dataGridViewMsg.Columns[e.ColumnIndex].ToString();
}
You're almost there: 你快到了:
Just do 做就是了
private void dataGridView1_CennEndEdit(object sender, DataGridViewCellEventArgs e)
{
int columnIndex = e.ColumnIndex;
}
That will give you the column index of the cell currently being edited. 这将为您提供当前正在编辑的单元格的列索引。
Though you would probably just want to use e.ColumnIndex
for whatever it is you want to do to save the overhead of creating a new variable. 尽管您可能只想使用e.ColumnIndex
来进行操作,以节省创建新变量的开销。 It isn't clear from your question what the end goal is. 从您的问题尚不清楚最终目标是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.