You're welcome, Einar. Have fun! =)
~~Bonnie
>Bonnie,
>Thanks it makes a lot of sense. Thanks for the ideas.
>
>Sincerely,
>Einar
>
>>Yeah, that's actually the way I do it, with one slight difference. I don't know if you're using the .NET base controls or your own classes sub-classed from the .NET controls (and you *should* be using sub-classes, BTW), but in my own classes, all my controls have a DataBind() method in which I remove existing DataBinding before re-binding ... that's where it should actually be handled, not by the control that's doing the databinding. So, assuming a DataBind() method for each TextBox, etc., the code simply needs to be this:
>>
>>public void DataBind(object BindTo)
>>{
>> if (BindTo is Class1)
>> {
>> Class1 o = (Class1)BindTo;
>>
>> this.numericUpDown1.DataBind(o, "N1");
>> this.numericUpDown2.DataBind(o, "N2");
>> this.checkBox1.DataBind(o, "C1");
>> }
>>}
>>
>>I hope I'm making sense. <g>
>>
>>~~Bonnie
>>
>>
>>
>>
>>>Bonnie,
>>>I had to make some slight "corrections" to the code you posted in the DataBind method. Code below shows the changes I had to make. Could you please review the changes and let me know what you think?
>>>
>>>The line "this.DataBindings.Clear();" I removed because I think it might be useless (well for me anyways).
>>>I had to clear the databindings for each control inside the usercontrol individually because the DataBind() method will be called several times with different instances of the Class1 class.
>>>
>>>Einar
>>>
>>>
>>>public void DataBind(object BindTo)
>>>{
>>> // removed the line below
>>> //this.DataBindings.Clear();
>>>
>>> if (BindTo is Class1)
>>> {
>>> // Added Clear() for the controls individually
>>> this.numericUpDown1.DataBindings.Clear();
>>> this.numericUpDown2.DataBindings.Clear();
>>> this.checkBox1.DataBindings.Clear();
>>>
>>> Class1 o = (Class1)BindTo;
>>>
>>> this.numericUpDown1.DataBindings.Add("Value", o, "N1");
>>> this.numericUpDown2.DataBindings.Add("Value", o, "N2");
>>> this.checkBox1.DataBindings.Add("Checked", o, "C1");
>>> }
>>>}
>>>
>>>
>>>>><snip>