datagridview vb.net 中的列特定点击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24320267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:44:36  来源:igfitidea点击:

column specific click event in datagridview vb.net

vb.netdatagridviewdatagridviewcolumn

提问by susiana

I have a dataGridView that has 2 columns called (colour & desc) and I want to have a click event that only fires on the (colour) column.

我有一个 dataGridView,它有 2 列,称为 (colour & desc),我想要一个仅在 (colour) 列上触发的单击事件。

I have searched a bit on the net and seen various ways to do this via row index but nothing by column index.

我在网上搜索了一下,看到了通过行索引执行此操作的各种方法,但没有通过列索引执行此操作。

Any help would be appreciated..,thank you

任何帮助将不胜感激..,谢谢

回答by Fabio

Create event handler for datagridview.CellClickevent

datagridview.CellClick事件 创建事件处理程序

Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
    Dim yourColumnIndex As Int32 = 1
    If e.ColumnIndex = yourColumnIndex Then
        'Do your staff
    End If
End Sub

Or if you have predefined columns then:

或者,如果您有预定义的列,则:

Private Sub dgv_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellClick
    If e.ColumnIndex = Me.colour.Index Then
        'Do your staff
    End If
End Sub