Datagridview Rowindex error message
I have a datagridview on my form. When the user clicks on a row, it executes code that reads data based on the value in column 0 of the selected row. I do not want to execute this code if the user clicks on the top header of the datagridview. I did some searching and came up with this:
Code:
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
If e.RowIndex < 1 Then Exit Sub
but I get an error message when I type it in that says "RowIndex is not a member of System.EventArgs". How can I rid of this error or otherwise distinguish between a click on a row and a click above the rows?
Re: Datagridview Rowindex error message
Try this:
Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex = -1 Then Return
MsgBox(e.RowIndex)
End Sub
Re: Datagridview Rowindex error message
Okay. So I used the wrong event? It appears to be working now. Thanks for the help.
Re: Datagridview Rowindex error message
You can quickly see what properties are available by inspecting the type of the e parameter, or within the handler in the code editor, type e. and intellisense will show a list of properties for the e parameter.
Re: Datagridview Rowindex error message
Sure. And with my original code, RowIndex was not listed for e. When you use the editor to create the code for cell click as opposed to click, e.SystemArg becomes e.Windows.Forms.DataGridViewCellEventArgs which does have RowIndex.