Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
4.00/5 (1 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:
C#
BindingSource bindingsource = new BindingSource();
DataSet ds = new DataSet("Preferences"); 

DataTable table = new DataTable("Preference");
table.Columns.Add("Value");

for (int i = 1; i <= 12; i++)
 { 
   table.Rows.Add(i); 
 }

ds.Tables.Add(table);
 
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
Updated 17-Oct-12 6:06am
v2

1 solution

Use the DataMemberChanged event in the BindingSource to validate your data
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900