C# 如何在单击DataGridView的特定单元格时引发单元格单击事件?

C# 如何在单击DataGridView的特定单元格时引发单元格单击事件?,c#,.net,winforms,datagridview,C#,.net,Winforms,Datagridview,任何人都可以在单击DataGridView的特定单元格(例如,列名为“EmployeeName”)时使用C#编码来帮助引发事件。处理CellContentClick事件,然后检查该列是否为您的列: if (e.ColumnIndex == clmEmployeeName.Index) 你可以试试这样的 DataGridViewCellEventArgs可用于确定该单元格在网格中的位置: DataGridViewCell cell = (DataGridViewCell) dataGridVi

任何人都可以在单击DataGridView的特定单元格(例如,列名为“EmployeeName”)时使用C#编码来帮助引发事件。

处理CellContentClick事件,然后检查该列是否为您的列:

if (e.ColumnIndex == clmEmployeeName.Index)

你可以试试这样的

DataGridViewCellEventArgs可用于确定该单元格在网格中的位置:

 DataGridViewCell cell = (DataGridViewCell) dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; 

 if (cell.ColumnIndex == this.dataGridView1.Columns["YourColumn"].Index) 
 { 
    // Do something when a "YourColumn" cell is clicked 
 } 
 else if (cell.ColumnIndex == this.dataGridView1.Columns["AnotherColumn"].Index) 
 { 
     // Do something when an "AnotherColumn" cell is clicked 
 }