Results 1 to 5 of 5

Thread: {Resolved} VB.NET 2005 - DataGridView - CellValidating

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    Resolved {Resolved} VB.NET 2005 - DataGridView - CellValidating

    Everytime I validate a cell in my datagridview, it enters in the event multi times. So If there is an error I see the messagebox many times and if the value is correct, it still makes the validation twice.

    EDIT:
    One thing I just noticed. If on a line a provoque an error, I get the error message twice. If I change line and provoque an error, I get the error message 3 times and it continues on an on 4-5-6-7-8 times ... so it always increases by one. Anyone can explain that ?


    Here is my code:


    Code:
        'This line is in the function where I fill the grid. 
        AddHandler grdInfo.CellValidating, AddressOf ValidateGridEntry 
    
        Private Sub ValidateGridEntry(ByVal sender As Object, ByVal e As Windows.Forms.DataGridViewCellValidatingEventArgs) 
    
            Dim lngRet As Long = 0 
    
            If e.RowIndex < 0 OrElse e.FormattedValue.ToString = String.Empty Then Exit Sub 
    
            If e.ColumnIndex = grdInfo.Columns("regCode").Index Then 
    
                lngRet = ValiderReglement(e.FormattedValue.ToString.Trim) 
                If lngRet = 0 Then 
    
                    ShowMessage(My.Resources.MSG_WARNING_CODE_REGLEMENT_INEXISTANT, mERROR) 
                    e.Cancel = True 
    
                Else 
    
                    If grdInfo.CommitEdit(DataGridViewDataErrorContexts.Commit) = False Then 
                        ShowMessage(My.Resources.MSG_WARNING_PROBLEME_COMMIT_CELLULE, mERROR) 
                    End If 
    
                End If 
    
            End If 
    
        End Sub
    Last edited by dbelley_office; Aug 8th, 2007 at 09:19 AM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    Re: VB.NET 2005 - DataGridView - CellValidating

    I am just moving up my message.
    I did not find a solution yet.

  3. #3
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: VB.NET 2005 - DataGridView - CellValidating

    Perhaps it has something to do with the Handler getting added multiple times mistakenly. I came upon something very similar when I was playing around with the DataGridView. Try removing any old handler before you add the new one.

    vb.net Code:
    1. 'This line is in the function where I fill the grid.
    2. RemoveHandler grdInfo.CellValidating, AddressOf ValidateGridEntry
    3. AddHandler grdInfo.CellValidating, AddressOf ValidateGridEntry

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    Re: VB.NET 2005 - DataGridView - CellValidating

    n madd !!

    You are my new hero !!

    Indeed, I have to call the function FillGrid at different times.
    I didn't know the "AddHandler" was adding everytimes.

    It is a good practice to always put the "RemoveHandler" line.

    Thank you big time !!

  5. #5
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: {Resolved} VB.NET 2005 - DataGridView - CellValidating

    Glad to help.

    Good luck on your project.

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