如何处理DataGridViewLinkColumn的点击事件 [英] How to handle the click event of DataGridViewLinkColumn

查看:42
本文介绍了如何处理DataGridViewLinkColumn的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C# 中有一个 WinForm.DataGridView 的列之一是 DataGridViewLinkColumn 类型.如何处理每列上的点击事件?

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 ?

这段代码似乎不起作用:

This code does not seem to work :

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的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆