How to handle the click event of DataGridViewLinkColumn

后端 未结 2 942
说谎
说谎 2021-01-01 21:48

I have a WinForm in C#. One of the column of the DataGridView is of type DataGridViewLinkColumn. How do I handle the click event on each column ?

2条回答
  •  攒了一身酷
    2021-01-01 22:24

    Why don't you use CellClick event handler, you can refer to corresponding column of each row, e.RowIndex by using e.ColumnIndex, as shown below:

    private void dataGridView1_CellClick(object sender,
        DataGridViewCellEventArgs e)
    {
        // here you can have column reference by using e.ColumnIndex
        DataGridViewImageCell cell = (DataGridViewImageCell)
            dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
    
        // ... do something ...
    }
    

提交回复
热议问题