Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
When I Build my project, I get the following error on my e.cancel statement:

'cancel' is not a member of 'System.Windows.Forms.DataGridViewCellEventArgs'

Here's the code in my event:

VB
Private Sub dgvPhysCME_CellValidating(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles dgvPhysCME.CellValueChanged

    'Bypass CellValidation when building/showing DataGridView
    If e.RowIndex = -1 Then Exit Sub

    'Clear ErrorText before testing cell value
    dgvPhysCME.Rows(e.RowIndex).ErrorText = ""

    'If cell is not null, exit sub
    If Not IsDBNull(dgvPhysCME.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) Then Exit Sub

    dgvPhysCME.Rows(e.RowIndex).ErrorText = "Field must not be empty"

    '*** This is where I'm getting the Build Error ***
    e.cancel = True

End Sub
Posted
Updated 5-Feb-11 3:52am
v3

You handle the wrong event.
It must be :
private void dgvPhysCME_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) Handles dgvPhysCME.CellValidating



The DataGridViewCellValidatingEventArgs has a Cancel property.

Cheers
 
Share this answer
 
Comments
Eddie Niebruegge 5-Feb-11 9:57am    
Thanks, Estys. That fixed the problem. If I remember correctly, I first created the event from the Properties/Event table, then edited what it gave me (obviously in error). Can you give me a reference point where I can go to see what properties other ...EventArgs have? Thanks again, Eddie
Estys 5-Feb-11 10:35am    
Specific for your ..Args :
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellvalidatingeventargs.aspx
You can navigate from there in the System.Windows.Forms namespace.
Or just google the ..EventArgs you want to look at, the are millions of them and not only in this namespace.
Eddie Niebruegge 5-Feb-11 11:24am    
Thanks again, Eddie
Try e.Cancel instead: C# and VB are case sensitive.
Additionally, you are using the wrong eventargs: DataGridViewCellValidatingEventArgs is what you should have. See MSDN[^] for details.
 
Share this answer
 
v2
Comments
Eddie Niebruegge 5-Feb-11 9:51am    
Thanks, OriginalGriff. You were half right. Changing the eventargs fixed the problem... thanks, again. However, although C# is case sensitive, VB isn't. Eddie
OriginalGriff 5-Feb-11 9:56am    
No you are right - it just should be! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900