Hi, all,
how does it work the databindings bidirectional between UIElements and one DataRow?
e.g. the Row has three columns (int, string datetime)
(1) Set Value from DataRow to UI
string s = myRow[1].ToString();
// remove all bindings
ultraCombo1.DataBindings.Clear();
ultraTextEditor1.DataBindings.Clear();
ultraCalendarCombo1.DataBindings.Clear();
// add new bindings
ultraTextEditor1.DataBindings.Add(new Binding("Text", s, "", true, DataSourceUpdateMode.OnValidation));
=> it works!
(2) Set Value from UI to DataRow
But after I change TextBox.Text, oder Datetime, I wish i can also see the changes on myRow...
I have tried these methods, but it does not work...
{
myRow.AcceptChanges();
myRow.EndEdit();
}
What's wrong? Many thanks!
Hi, Mike, thanks for your answer!
yes, you are right. actually I do not need "OnValidating"...
But the correct code like that: ultraTextEditor1.DataBindings.Add(new Binding("Text", myRow.Table, ""))
comment: the row should exist in one datatable.
Best wishes
I'm not sure what kind of example you are looking for. You don't need to handle the Validating event unless you want to. The problem is that if you specify OnValidating (as you did in your original post), then the BindingManager will probably only copy the value form the control into the data source when the Validating event fires - and this event doesn't fire unless the user makes a change and loses focus on the control.
If you are updating values in code, it would probably be a lot easier for you to simply update the data source, rather than updating a control in the UI.
Hi, Mike, thanks for your reply :-)
I have not called the Validate method for any controls on the form.
Could you give me example about the validating?
if I only use:
ultraTextEditor1.DataBindings.Add(new Binding("Text", s, ""))
=> Do I also need ultraTextEditor1_Validating{ ... ??? .... }
Thanks & Greetings
Hi,
The way you have your binding set up, it looks like the underlying data row will only be updated when the Validating event of the control fires. So this means it will only work if the user edits the field and then moves to another control. I suspect that if you set the value of one of these controls in code, the control will never update the underying data source, unless you can somehow force it's Validating event to fire. Have you tried calling the Validate method on the form?