Results 1 to 4 of 4

Thread: [RESOLVED] [2005] DataGridView CellValidated Event Issues

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Resolved [RESOLVED] [2005] DataGridView CellValidated Event Issues

    I have a DataGridView bound to a DataSet on my form. When the user clicks on the Cancel button, I call DataSet.Clear and reset the various parts of the form to get it ready for new data input.

    The problem is that if the user is in the DGV when Cancel is clicked and DataSet.Clear is called, then the CellValidated event fires and gives an IndexOutOfRangeException.

    The following exception occurred in the DataGridView:
    System.IndexOutOfRangeException: Index 0 does not have a value.
    at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
    at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 rowindex)


    This is firing on the first line of the following block of code:

    Code:
            If Not String.IsNullOrEmpty(dgv.Rows(e.RowIndex).ErrorText.Trim) Then
                dgv.Rows(e.RowIndex).ErrorText = String.Empty
            End If
    I had this same thing happen in a previous app and I just created an IsResetting form-level boolean. On click of Cancel, I would set it to True and then any routines that gave problems, I would have them watch the IsResetting and if True, don't process the routine.

    I would rather not go the route of the IsResetting boolean. I am hoping that there is some way of looking at the control or the DataSet and knowing what state everything is in.


    EDIT:
    I have determined that I can access the data in the cells of the DGV. The error happens when I look at the ErrorText property for the DGV Row object.
    Last edited by Aspnot; Sep 24th, 2007 at 08:50 AM.
    My.Settings.Signature = String.Empty

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