简体   繁体   中英

How to check the header text of a DataGridView column of a selected cell in Visual Basic

I have a datagridview in visual basic. I want to adjust a sub to accomplish the following task: When a user selects a cell in my DGV (Cell Click event) I want to check the column header text. And in my example, if the header text of the column is "MinEquation" then I want to execute some event. The reason I cannot use column indices is that I create these DGV's dynamically in a loop with different datatables. How can I do a comparison operator on the column header text of my selected cell. Thank you!

You would generate the DataGridView's CellClick event and then use the DataGridViewCellEventArgs to return the column's information. Take a look at this example:

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    If DataGridView1.Columns(e.ColumnIndex).HeaderText = "MinEquation" Then
        'Match
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM