开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜