How to raise cell click event on clicking the particular cell of DataGridView?
Anyone Please help with C# coding for how to raise the event when the particular cell (for exampl开发者_如何学编程e, column name is "EmployeeName") of DataGridView is clicked.
Handle the CellContentClick event, then check if the column is your column:
if (e.ColumnIndex == clmEmployeeName.Index)
you could try something like this ..
The DataGridViewCellEventArgs can be used to determine what the position of that cell in the grid is:
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
}
精彩评论