473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 tablebindignnavigator.
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 TblCompanyDataGridView_CellValidating(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellValidatingEve ntArgs) Handles
TblCompanyDataGridView.CellValidating
Me.TblCompanyDataGridView.Rows(e.RowIndex).ErrorTe xt = ""

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

' editing since there

' is not any point in validating its initial value.

If TblCompanyDataGridView.Rows(e.RowIndex).IsNewRow Then Return

'This validates the closing

If TblCompanyDataGridView.Columns(e.ColumnIndex).Name = "dgvCellIsClosed"
Then

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

If e.FormattedValue.Equals(True) Then

Dim brv As Boolean

brv =
ValidateCompanyClosing(CType(TblCompanyDataGridVie w.Rows(e.RowIndex).Cells.Item(0).Value,
Integer)) ' the validating procedure returns false for testing

If Not brv Then

If
System.Globalization.CultureInfo.CurrentUICulture. TwoLetterISOLanguageName =
"fr" Then

Me.TblCompanyDataGridView.Rows(e.RowIndex).ErrorTe xt = "Fermeture de
compagnie défendue, vérifiez les conditions nécessaires dans la
documentation."

Else

Me.TblCompanyDataGridView.Rows(e.RowIndex).ErrorTe xt = "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.TblCompanyBindingSource.EndEdit()

Me.TblCompanyTableAdapter.Update(Me.DsCompanyInfo. tblCompany)

Me.TblCompanyAddressesBindingSource.EndEdit()

Me.TblCompanyAddressesTableAdapter.Update(Me.DsCom panyInfo.tblCompanyAddresses)

Me.TblCompanyPhonesBindingSource.EndEdit()

Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompan yInfo.tblCompanyPhones)

If
System.Globalization.CultureInfo.CurrentUICulture. TwoLetterISOLanguageName =
"fr" Then

MsgBox("Sauvegarde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Message)

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 3254
Hi,

"Bob" <bd*****@sgiims.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In a winform with a datagridview using cellvalidating event but also have
a save button that is located on a tablebindignnavigator.
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 BindingNavigator 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.TblCompanyBindingSource.EndEdit()

Me.TblCompanyTableAdapter.Update(Me.DsCompanyInfo. tblCompany)

Me.TblCompanyAddressesBindingSource.EndEdit()

Me.TblCompanyAddressesTableAdapter.Update(Me.DsCom panyInfo.tblCompanyAddresses)

Me.TblCompanyPhonesBindingSource.EndEdit()

Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompan yInfo.tblCompanyPhones)

If
System.Globalization.CultureInfo.CurrentUICulture. TwoLetterISOLanguageName
= "fr" Then

MsgBox("Sauvegarde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Message)

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**************@TK2MSFTNGP14.phx.gbl...
Hi,

"Bob" <bd*****@sgiims.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In a winform with a datagridview using cellvalidating event but also have
a save button that is located on a tablebindignnavigator.
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 BindingNavigator 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.TblCompanyBindingSource.EndEdit()

Me.TblCompanyTableAdapter.Update(Me.DsCompanyInfo. tblCompany)

Me.TblCompanyAddressesBindingSource.EndEdit()

Me.TblCompanyAddressesTableAdapter.Update(Me.DsCom panyInfo.tblCompanyAddresses)

Me.TblCompanyPhonesBindingSource.EndEdit()

Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompan yInfo.tblCompanyPhones)

If
System.Globalization.CultureInfo.CurrentUICulture. TwoLetterISOLanguageName
= "fr" Then

MsgBox("Sauvegarde réussie!")

Else

MsgBox("Save completed!")

End If

Catch ex As Exception

MsgBox(ex.Message)

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
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
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...
1
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...
3
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...
3
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...
6
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...
21
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...
1
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...
0
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...

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.