473,714 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to trap if a cancel has occurred on cell validation?

Bob
In a winform with a datagridview using cellvalidating event but also have a
save button that is located on a tablebindignnav igator.
The behaviour I observe is that if the cellvalidating issues a cancel = true
after the save button has been clicked, the update statements in the click
event of the save button still occur but nothing gets saved, which is OK.
Except that I pop a message box in the click event after the update
statements have been successfully executed (they're in a try catch
construct) to say Save completed.

This gives me the situation where Cellvalidating issues a false cxancels the
update, the save does not occur, but my user gets message Save succeeded!
This is the code in the cellvalidating event.

Private Sub TblCompanyDataG ridView_CellVal idating(ByVal sender As Object,
ByVal e As System.Windows. Forms.DataGridV iewCellValidati ngEventArgs) Handles
TblCompanyDataG ridView.CellVal idating
Me.TblCompanyDa taGridView.Rows (e.RowIndex).Er rorText = ""

' Don't try to validate the 'new row' until finished

' editing since there

' is not any point in validating its initial value.

If TblCompanyDataG ridView.Rows(e. RowIndex).IsNew Row Then Return

'This validates the closing

If TblCompanyDataG ridView.Columns (e.ColumnIndex) .Name = "dgvCellIsClose d"
Then

'If CType(e.Formatt edValue, String) = "1" Then

If e.FormattedValu e.Equals(True) Then

Dim brv As Boolean

brv =
ValidateCompany Closing(CType(T blCompanyDataGr idView.Rows(e.R owIndex).Cells. Item(0).Value,
Integer)) ' the validating procedure returns false for testing

If Not brv Then

If
System.Globaliz ation.CultureIn fo.CurrentUICul ture.TwoLetterI SOLanguageName =
"fr" Then

Me.TblCompanyDa taGridView.Rows (e.RowIndex).Er rorText = "Fermeture de
compagnie défendue, vérifiez les conditions nécessaires dans la
documentation."

Else

Me.TblCompanyDa taGridView.Rows (e.RowIndex).Er rorText = "Closing forbidden,
see necessary conditions in documentation."

End If

e.Cancel = True

End If

End If

End If
End Sub

This is the code that does the updates

Private Sub SaveCompanyInfo ()

Try

Me.Validate()

Me.TblCompanyBi ndingSource.End Edit()

Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompany Info.tblCompany )

Me.TblCompanyAd dressesBindingS ource.EndEdit()

Me.TblCompanyAd dressesTableAda pter.Update(Me. DsCompanyInfo.t blCompanyAddres ses)

Me.TblCompanyPh onesBindingSour ce.EndEdit()

Me.TblCompanyPh onesTableAdapte r.Update(Me.DsC ompanyInfo.tblC ompanyPhones)

If
System.Globaliz ation.CultureIn fo.CurrentUICul ture.TwoLetterI SOLanguageName =
"fr" Then

MsgBox("Sauvega rde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

End Sub

Bfore I execute the msgbox, I should know if a cancel has been issued by any
cellvalidating events in any of the datagridviews on te form- there are two
others.

How do i determine that. Ther does not seem to be an event in any of the
datasets or the datagridviews that indicates that a cancel has occured.

Any help would be greatly appreciated.

Bob


Jan 7 '06 #1
2 3290
Hi,

"Bob" <bd*****@sgiims .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In a winform with a datagridview using cellvalidating event but also have
a save button that is located on a tablebindignnav igator.
The behaviour I observe is that if the cellvalidating issues a cancel =
true after the save button has been clicked, the update statements in the
click event of the save button still occur but nothing gets saved,
The current (invalid) record may not be saved, but if the user had a chance
to change other records before that then those records will still be saved.
which is OK. Except that I pop a message box in the click event after the
update statements have been successfully executed (they're in a try catch
construct) to say Save completed.

This gives me the situation where Cellvalidating issues a false cxancels
the update, the save does not occur, but my user gets message Save
succeeded!
This is the code in the cellvalidating event.
[code snipped]

This is the code that does the updates

Private Sub SaveCompanyInfo ()

Try

Me.Validate()
Because the BindingNavigato r doesn't cause validation, it is postponed until
here, Validate() performs the last validation and returns the result.

Dim validateOK As Boolean = Me.Validate()
HTH,
Greetings

Me.TblCompanyBi ndingSource.End Edit()

Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompany Info.tblCompany )

Me.TblCompanyAd dressesBindingS ource.EndEdit()

Me.TblCompanyAd dressesTableAda pter.Update(Me. DsCompanyInfo.t blCompanyAddres ses)

Me.TblCompanyPh onesBindingSour ce.EndEdit()

Me.TblCompanyPh onesTableAdapte r.Update(Me.DsC ompanyInfo.tblC ompanyPhones)

If
System.Globaliz ation.CultureIn fo.CurrentUICul ture.TwoLetterI SOLanguageName
= "fr" Then

MsgBox("Sauvega rde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

End Sub

Bfore I execute the msgbox, I should know if a cancel has been issued by
any cellvalidating events in any of the datagridviews on te form- there
are two others.

How do i determine that. Ther does not seem to be an event in any of the
datasets or the datagridviews that indicates that a cancel has occured.

Any help would be greatly appreciated.

Bob


Jan 7 '06 #2
Bob
Thanks
"Bart Mermuys" <bm************ *@hotmail.com> wrote in message
news:O0******** ******@TK2MSFTN GP14.phx.gbl...
Hi,

"Bob" <bd*****@sgiims .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In a winform with a datagridview using cellvalidating event but also have
a save button that is located on a tablebindignnav igator.
The behaviour I observe is that if the cellvalidating issues a cancel =
true after the save button has been clicked, the update statements in the
click event of the save button still occur but nothing gets saved,


The current (invalid) record may not be saved, but if the user had a
chance to change other records before that then those records will still
be saved.
which is OK. Except that I pop a message box in the click event after the
update statements have been successfully executed (they're in a try catch
construct) to say Save completed.

This gives me the situation where Cellvalidating issues a false cxancels
the update, the save does not occur, but my user gets message Save
succeeded!
This is the code in the cellvalidating event.

[code snipped]

This is the code that does the updates

Private Sub SaveCompanyInfo ()

Try

Me.Validate()


Because the BindingNavigato r doesn't cause validation, it is postponed
until here, Validate() performs the last validation and returns the
result.

Dim validateOK As Boolean = Me.Validate()
HTH,
Greetings

Me.TblCompanyBi ndingSource.End Edit()

Me.TblCompanyTa bleAdapter.Upda te(Me.DsCompany Info.tblCompany )

Me.TblCompanyAd dressesBindingS ource.EndEdit()

Me.TblCompanyAd dressesTableAda pter.Update(Me. DsCompanyInfo.t blCompanyAddres ses)

Me.TblCompanyPh onesBindingSour ce.EndEdit()

Me.TblCompanyPh onesTableAdapte r.Update(Me.DsC ompanyInfo.tblC ompanyPhones)

If
System.Globaliz ation.CultureIn fo.CurrentUICul ture.TwoLetterI SOLanguageName
= "fr" Then

MsgBox("Sauvega rde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

End Sub

Bfore I execute the msgbox, I should know if a cancel has been issued by
any cellvalidating events in any of the datagridviews on te form- there
are two others.

How do i determine that. Ther does not seem to be an event in any of the
datasets or the datagridviews that indicates that a cancel has occured.

Any help would be greatly appreciated.

Bob



Jan 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
73211
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
0
5421
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this board. I have a form that contains a ListView and a GroupBox control. The GroupBox control itself contains several TextBox Controls. I have Validating and Validated event handlers set for the GroupBox control, and a SelectedIndexChanged event...
1
5475
by: Corey Olsen | last post by:
Can anyone point me to some documentation on bypassing validation controls when a user selects cancel? What I have is a user control with a form to fill out information on a subject. The user should be presented with two buttons a "Submit" and a "Cancel". When the "Cancel" button is selected all of the items on the user control should be cleared. However, I have validation controls setup for each item necessary on the form and when...
3
3697
by: news.public.microsoft.com | last post by:
Hi everyone, I have a VB.NET web form with some field validators and Save and Cancel buttons. What I want to do is on the Cancel button On_Click event, Response.Redirect to another page. The problem is that the client-side validation occurs before even reaching the event for the Cancel button. I've tried some ways to disable only the client-side validation, but I find it a poor design that you can't have a command button bypass the...
3
2409
by: MB | last post by:
Hi, I am doing a project which uses asp.net to develop its forms. The form uses validation web controls to validate the data entered in text boxes. When Cancel Button is pressed which is to exit from the current page and go to the previous page, the validation controls activate because data has not been entered, and the user cannot cancel. I have used Response.Redirect(webpage) but the validations activates and unless I enter some data...
6
4963
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging event of a datatable, from two seperate classes. I wish to do some data validating. Due to the nature of the data validation being done, I seperated this code in two classes.
21
9211
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
1
6197
by: Frank O'Hara | last post by:
I think I'm losing my mind, granted it is kind of late here so... I'm trying to do some simple validation on the client as keys are pressed. The validation routine works well enough however I can't seem to cancel the event should the validation fail. Well more accurately, I can't cancel the keyup event. When I hook the following routine to the keydown event it works well and an invalidation cancels the event. I'm hooking the...
0
1421
by: David C | last post by:
I have a GridView with a Delete link and wondered where the best place was to check and cancel delete of a row/record that is bound to an SqlDatasource. I can use datasource Deleting event or GridView_RowDeleting event. I need to get 2 values from the row I am trying to delete so I can perform another function returns whether I can delete the record or not. I am trying to do this in gridview event (see code below) but it is not working....
0
9306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9168
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7942
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3155
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.