Click here to Skip to main content
13,200,729 members (53,425 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I appreciate if anyone can advise if there is event handler or other ways to validate changes from a data binded textbox before updating data source. I have a windows form with a data repeater. In the data repeater, I have a textbox which is data binded as follows:
BindingSource bindingsource = new BindingSource();
DataSet ds = new DataSet("Preferences"); 
DataTable table = new DataTable("Preference");
for (int i = 1; i <= 12; i++)
bindingsource.DataSource = ds;
bindingsource.DataMember = "Preference";           
textBox1.DataBindings.Add(new Binding("Text", bindingsource, "Value", true, DataSourceUpdateMode.OnValidation)); 

As can be seen in the code, I have set the textbox to DataSourceUpdateMode.OnValidation. When I ran the project and change the textbox value on the form, I can see that the dataset (ds) is updated correctly. However, I want to be able to validate my entry before committing the new value into my data source.

Is there a special way, using handler or interface to do this please?
Posted 17-Oct-12 6:05am
Updated 17-Oct-12 6:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the DataMemberChanged event in the BindingSource to validate your data

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 21 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100