如何处理DataGridViewLinkColumn的click事件 [英] How to handle the click event of DataGridViewLinkColumn
本文介绍了如何处理DataGridViewLinkColumn的click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中有一个WinForm。 DataGridView
的列之一为 DataGridViewLinkColumn
类型。我如何处理每一列上的click事件?
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 ?
此代码似乎不起作用:
private void UserDataTable_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//Code here
}
例如,如果我有10行,每当我单击与 DataGridViewLinkColumn
,我应该能够处理它。
For instance, if I have 10 rows, whenever I click the content of each row corresponding to the column "DataGridViewLinkColumn
", I should be able to handle it.
谢谢
推荐答案
为什么不使用 CellClick
事件处理程序,可以引用每行的相应列 e.RowIndex
使用 e.ColumnIndex
,如下所示:
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 ...
}
这篇关于如何处理DataGridViewLinkColumn的click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文