开发者

How to raise cell click event on clicking the particular cell of DataGridView?

开发者 https://www.devze.com 2023-03-08 08:56 出处:网络
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 CellContentC

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 
 } 
0

精彩评论

暂无评论...
验证码 换一张
取 消