CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2002
    Posts
    10,943

    DataGridView ignore index out of bounds

    Is there a way to force my application to ignore the index out of bounds error from the DataGridView? I have gone through from top to bottom and there is no reason why I should be receiving this error. No operations, rows, nor columns are affected by just continuing past the error.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

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

    Re: DataGridView ignore index out of bounds

    The following is actually bad advice.

    You could add a Try and catch block, and provide nothing in the catch section, as in :
    Code:
    Try
    ' Your Code Here
    Catch ex As IndexOutOfBoundsException
    'Do Nothing Here, Leave Empty!
    End Try
    Now, whenever you get this exception, it gets "skipped", because we said nothing should happen when it occurs.

    The whole reason why I said it is bad advice actually, is because, this type of exception may influence other parts of your code / program.

    You said :
    and there is no reason why I should be receiving this error
    This is where the Good advice comes in

    There is always a reason for an error, sometimes it may just not be very obvious, I'd actually recommend having a closer look at all the particular code, propertis set etc.

    I hope my comments wre useful... And Good luck!

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: DataGridView ignore index out of bounds

    Here's my exact predicament...it makes no sense to me.

    • I have a CSV file which loads to a DataGridView perfectly fine. No error whatsoever.
    • If I click a column so that it sorts, I receive the error.
    • However, if I click another column so that the sort order (asc, desc) is the same, but the column is different, I don't see the error again.
    • But, it seems that the moment asc or desc is changed, that's when I receive the error.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: DataGridView ignore index out of bounds

    What code do you use for Sorting, did you write your own custom code ¿

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: DataGridView ignore index out of bounds

    No custom code whatsoever. I just let the DataGridView handle it, itself.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: DataGridView ignore index out of bounds

    Interesting ...

    Is it possible to add your CSV file and form with the DGV on it here, your project / smaller representation of it ¿

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: DataGridView ignore index out of bounds

    Unfortunately, I cannot. It is a sensitive document. The whole things is based upon login information and accounts. I would pretty much have to create a fake one to do so.

    Here's the format: firstname, lastname, username, password, email, address, phone, datecreated, dateexpires
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: DataGridView ignore index out of bounds

    I have an idea...I'm going to remove the last line return of the document. Since I am temporarily adding to each line as it is read into the DataGridView, I bet this is creating a problem.

    I'll post back as soon as I try it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: DataGridView ignore index out of bounds

    OK, no prob .

    Last question ( sorry for all these questions, I'm just trying to narrow down the issue )
    Does it always happen with the same column, or does it happen with any of these columns ¿

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: DataGridView ignore index out of bounds

    Can happen on any column so long as the asc/desc is changed.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: DataGridView ignore index out of bounds

    Can you explain this a little better?

    * If I click a column so that it sorts, I receive the error.
    * However, if I click another column so that the sort order (asc, desc) is the same, but the column is different, I don't see the error again.
    * But, it seems that the moment asc or desc is changed, that's when I receive the error.
    Sort EMAIL to ASC. Error
    Change NAME ... ? (was unsorted before, right)

    Thanks
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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