CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2021
    Posts
    6

    Datagridview Header

    Hi,

    On my datagridview cellmouseclick event I have this code:

    Code:
    Index = e.RowIndex
            Dim selectedRow As DataGridViewRow
            selectedRow = DgTenantDetails.Rows(index)
    Now, at runtime when I click any cell on the header I receive the error message:

    Code:
    System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index'
    What is wrong?

    Thank you!

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Datagridview Header

    Two things:
    You are finding the RowIndex, but you click the Column header?
    The first code snippet will work perfect when you click inside the row inside the grid, hence the message.
    Second thing: have a look into the ColumnHeaderMouseClick event to capture column headr events

    Hannes

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

Featured