|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to trap if a cancel has occurred on cell validation?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.DataGridViewCellValidatingEventArgs) Handles TblCompanyDataGridView.CellValidating Me.TblCompanyDataGridView.Rows(e.RowIndex).ErrorText = "" ' 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(TblCompanyDataGridView.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).ErrorText = "Fermeture de compagnie défendue, vérifiez les conditions nécessaires dans la documentation." Else Me.TblCompanyDataGridView.Rows(e.RowIndex).ErrorText = "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.DsCompanyInfo.tblCompanyAddresses) Me.TblCompanyPhonesBindingSource.EndEdit() Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompanyInfo.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 Hi,
"Bob" <bduf***@sgiims.com> wrote in message The current (invalid) record may not be saved, but if the user had a chance news:%23SSnXCyEGHA.1312@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, to change other records before that then those records will still be saved. Show quoteHide quote > which is OK. Except that I pop a message box in the click event after the Because the BindingNavigator doesn't cause validation, it is postponed until > 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() here, Validate() performs the last validation and returns the result. Dim validateOK As Boolean = Me.Validate() HTH, Greetings Show quoteHide quote > > Me.TblCompanyBindingSource.EndEdit() > > Me.TblCompanyTableAdapter.Update(Me.DsCompanyInfo.tblCompany) > > Me.TblCompanyAddressesBindingSource.EndEdit() > > Me.TblCompanyAddressesTableAdapter.Update(Me.DsCompanyInfo.tblCompanyAddresses) > > Me.TblCompanyPhonesBindingSource.EndEdit() > > Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompanyInfo.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 > > > > > > Thanks
Show quoteHide quote "Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message news:O0IgXlyEGHA.3000@TK2MSFTNGP14.phx.gbl... > Hi, > > "Bob" <bduf***@sgiims.com> wrote in message > news:%23SSnXCyEGHA.1312@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.DsCompanyInfo.tblCompanyAddresses) >> >> Me.TblCompanyPhonesBindingSource.EndEdit() >> >> Me.TblCompanyPhonesTableAdapter.Update(Me.DsCompanyInfo.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 >> >> >> >> >> >> > >
Armin - Start sound problem revived in new thread
Use of delegate Loading data in the flexgrid takes long time adding asynchronous support VB 2003 - Odd Bug in My Program Paging, Filtering and Sorting Simple Example of How to Implement SerialPort Class Db Interaction spped issue with upgraded code from vb6 to vb.net Add a line break in label.text populating text boxes... |
|||||||||||||||||||||||