Results 1 to 5 of 5

Thread: Datagridview Rowindex error message

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    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?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Datagridview Rowindex error message

    Okay. So I used the wrong event? It appears to be working now. Thanks for the help.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width