任何人请点击C#编码,了解如何在点击DataGridView的特定单元格(例如,列名为“EmployeeName”)时引发事件。
答案 0 :(得分:2)
处理CellContentClick事件,然后检查列是否是您的列:
if (e.ColumnIndex == clmEmployeeName.Index)
答案 1 :(得分:0)
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
}