|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Validating Data Using a Error ProviderA binding navigator control adds the following code for when the Save button is clicked:
Me.Validate() Me.UserBindingSource.EndEdit() Me.UserTableAdapter.Update(Me.UserDataSet.User)" You can add code to the column changing event for the dataset by using the dataset designer, for example: Private Sub UserDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging If (e.Column.ColumnName = Me.WindowsLoginColumn.ColumnName) Then If CType(e.ProposedValue, String) = "" Then e.Row.SetColumnError(e.Column, "Cannot be blank") Else e.Row.SetColumnError(e.Column, "") End If End If The problem is, the validation is not actually done until the .EndEdit event is fired. Me.Validate can be overriden for form validation (not validation on the dataset columns). So EndEdit throws a runtime error say if you have Null for a column that does not allow Nulls. I'm having a very hard time getting my validation to work using the error provider rather than throwing runtime errors. Help! Ok I'm just going to use form validation and column validation I guess (seems silly). How do I return false since the controls_validating is a sub and not a function?
"Ryan" <Tyveil@newsgroups.nospam> wrote in message news:O%23IuTZHoGHA.4176@TK2MSFTNGP05.phx.gbl... A binding navigator control adds the following code for when the Save button is clicked:Me.Validate() Me.UserBindingSource.EndEdit() Me.UserTableAdapter.Update(Me.UserDataSet.User)" You can add code to the column changing event for the dataset by using the dataset designer, for example: Private Sub UserDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging If (e.Column.ColumnName = Me.WindowsLoginColumn.ColumnName) Then If CType(e.ProposedValue, String) = "" Then e.Row.SetColumnError(e.Column, "Cannot be blank") Else e.Row.SetColumnError(e.Column, "") End If End If The problem is, the validation is not actually done until the .EndEdit event is fired. Me.Validate can be overriden for form validation (not validation on the dataset columns). So EndEdit throws a runtime error say if you have Null for a column that does not allow Nulls. I'm having a very hard time getting my validation to work using the error provider rather than throwing runtime errors. Help! Hi Ryan,
Thank you for your post. Based on my understanding, your question is how to use ErrorProvider to display errors when working with a DataSet. If I've misunderstood anything, please feel free to post here. First, please take a look at following MSDN Library article: #Walkthrough: Adding Validation to a Dataset http://msdn2.microsoft.com/en-us/library/ms171930.aspx From this example, we will see that the ErrorProvider is working when you move focus away from the field. This will give the user a visual clue of which field is filled wrong value. Also, the validation will only work when you changed the field's value. Hope this helps. Please feel free to post here if anything is unclear. Regards, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Hi Walter,
I actually used that walkthrough prior to this post. There are 2 problems with it. 1) If the user put's nothing in the field (leaves it blank), the ErrorProvider does not appear. If using the ErrorProvider control during the control's (text box for example) validating event rather than in the dataset, it works whether the user enters anything or not, it validates when the control loses focus whereas the dataset column_changing validating event only occurs if the field has changed. 2) Just because the error provider error is set (using seterror()), it still does not stop the database update from happening. So if the field contains something that violates the dataset integrity a runtime error will occur. Perhaps a try-catch block that does nothing in the catch block is the way to go (since the ErrorProvider handles informing the user of the input error). Ryan Show quoteHide quote "Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message news:CivL0XPoGHA.4260@TK2MSFTNGXA01.phx.gbl... > Hi Ryan, > > Thank you for your post. > > Based on my understanding, your question is how to use ErrorProvider to > display errors when working with a DataSet. If I've misunderstood > anything, > please feel free to post here. > > First, please take a look at following MSDN Library article: > > #Walkthrough: Adding Validation to a Dataset > http://msdn2.microsoft.com/en-us/library/ms171930.aspx > > From this example, we will see that the ErrorProvider is working when you > move focus away from the field. This will give the user a visual clue of > which field is filled wrong value. Also, the validation will only work > when > you changed the field's value. > > Hope this helps. Please feel free to post here if anything is unclear. > > Regards, > Walter Wang (waw***@online.microsoft.com, remove 'online.') > Microsoft Online Community Support > > ================================================== > When responding to posts, please "Reply to Group" via your newsreader so > that others may learn and benefit from your issue. > ================================================== > > This posting is provided "AS IS" with no warranties, and confers no > rights. > Hmmm I tried the try-catch block but it seems the error occurs before the
DataTable_ColumnChanging event occurs (where the validation takes place). So if a field violates database integrity, nothing happens. Show quoteHide quote "Ryan" <Tyveil@newsgroups.nospam> wrote in message news:%23uocl3PoGHA.4688@TK2MSFTNGP03.phx.gbl... > Hi Walter, > > I actually used that walkthrough prior to this post. There are 2 problems > with it. > 1) If the user put's nothing in the field (leaves it blank), the > ErrorProvider does not appear. If using the ErrorProvider control during > the control's (text box for example) validating event rather than in the > dataset, it works whether the user enters anything or not, it validates > when the control loses focus whereas the dataset column_changing > validating event only occurs if the field has changed. > 2) Just because the error provider error is set (using seterror()), it > still does not stop the database update from happening. So if the field > contains something that violates the dataset integrity a runtime error > will occur. Perhaps a try-catch block that does nothing in the catch block > is the way to go (since the ErrorProvider handles informing the user of > the input error). > > Ryan > > "Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message > news:CivL0XPoGHA.4260@TK2MSFTNGXA01.phx.gbl... >> Hi Ryan, >> >> Thank you for your post. >> >> Based on my understanding, your question is how to use ErrorProvider to >> display errors when working with a DataSet. If I've misunderstood >> anything, >> please feel free to post here. >> >> First, please take a look at following MSDN Library article: >> >> #Walkthrough: Adding Validation to a Dataset >> http://msdn2.microsoft.com/en-us/library/ms171930.aspx >> >> From this example, we will see that the ErrorProvider is working when you >> move focus away from the field. This will give the user a visual clue of >> which field is filled wrong value. Also, the validation will only work >> when >> you changed the field's value. >> >> Hope this helps. Please feel free to post here if anything is unclear. >> >> Regards, >> Walter Wang (waw***@online.microsoft.com, remove 'online.') >> Microsoft Online Community Support >> >> ================================================== >> When responding to posts, please "Reply to Group" via your newsreader so >> that others may learn and benefit from your issue. >> ================================================== >> >> This posting is provided "AS IS" with no warranties, and confers no >> rights. >> > > Hi Ryan,
Thank you for your post. Using the DataTable's ColumnChanging event, it must occur after you changed the data, so for a default empty field, this event will not be triggered, thus the ErrorProvider didn't appear. I recommend you take a look at following article: #Extending Windows Forms with a Custom Validation Component Library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm l/winforms03162004.asp With this custom validation component library, you can use these validators and check each validator's IsValid property after you called "Validate" method in the save button's click event. If any validator is invalid, don't call remaining "EndEdit" and "TableAdapter.Update". Hope this helps. Please feel free to post here if anything is unclear. Regards, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
timer control
TreeView control checked based on if records exist What exactly does it mean when they say CopyFile() and Progress Bar? CreateInstance and late binding what is best practice to populate large combobox? VB 2005 Newbie - Binding? No of files in folder Data binding to an object Somebody please help - Request for the permission of type 'System.Web.AspNetHostingPermission' [...] |
|||||||||||||||||||||||