|
-
Aug 7th, 2007, 01:09 PM
#1
Thread Starter
Hyperactive Member
{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.
-
Aug 8th, 2007, 08:31 AM
#2
Thread Starter
Hyperactive Member
Re: VB.NET 2005 - DataGridView - CellValidating
I am just moving up my message.
I did not find a solution yet.
-
Aug 8th, 2007, 08:37 AM
#3
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:
'This line is in the function where I fill the grid.
RemoveHandler grdInfo.CellValidating, AddressOf ValidateGridEntry
AddHandler grdInfo.CellValidating, AddressOf ValidateGridEntry
-
Aug 8th, 2007, 09:14 AM
#4
Thread Starter
Hyperactive Member
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 !!
-
Aug 8th, 2007, 09:22 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|