DataGridView header text

bcorbett

Active member
Joined
Oct 16, 2006
Messages
27
Programming Experience
Beginner
I want to get the header text of the column when I click on a cell. I also want to get the value of the cell in the first column in the same row as the cell that I click on. not real sure how to do this.

Could someone help me on this? Thanks in advance!!
 
VB.NET:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick
    Dim dgv As DataGridView = sender
    Dim headertext As String = dgv.Columns(e.ColumnIndex).HeaderText
    Dim rowfirstcell As String = dgv.Item(0, e.RowIndex).Value
    Dim fmt As String = "headertext: {0} {1}value first cell in row: {2}"
    MsgBox(String.Format(fmt, headertext, vbNewLine, rowfirstcell))
End Sub
 
Back
Top