Databinding

  • Thread starter Thread starter Eduard Meusburger
  • Start date Start date
E

Eduard Meusburger

I have created a UserControl which inherits from textbox.
Then I made a additional property.
Now I can bind the additional property to a field in the
datasource.
The new property is set through databinding, but when i
set the property in the program, the datasource is not
updated.
I have tried to implement a propertyChanged event but it
still does not work.
Can someone tell me how to implement the propertyChanged
event for a custom property for updateting the datasource
in C#.

Thanks in advance
Eduard
 
Hi Eduard,

A kinda dumb question but here goes: have you ensured that the event
implemented is named after the property name (that is, if you have a
property called CustomProperty, the event should be CustomPropertyChanged)?
 
Hello Dimitry

Here the code for the property and the event of my custom
textbox;

public event EventHandler Text2Changed;
private string text2 ="";

public string Text2{
get{return text2;}
set{
if ( text2 != value ){
text2 = value;
if (Text2Changed != null){
Text2Changed(this, EventArgs.Empty);
}
}
}


In my form i set the databinding as follows:

textbox1.Databindings.Add("Text",
dataSet11.Customers, "CompanyName");
textbox1.DataBindings.Add("Text2",
dataSet11.Customers, "ContactName");

In the click event of a button i set the Text2 property
to "MyContact".

The event Text2Changed in the set of the Text2 property is
raised, but the datasource is not updated.



When i set text Text2 property of my textbox

-----Original Message-----
Hi Eduard,

A kinda dumb question but here goes: have you ensured that the event
implemented is named after the property name (that is, if you have a
property called CustomProperty, the event should be CustomPropertyChanged)?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I have created a UserControl which inherits from textbox.
Then I made a additional property.
Now I can bind the additional property to a field in the
datasource.
The new property is set through databinding, but when i
set the property in the program, the datasource is not
updated.
I have tried to implement a propertyChanged event but it
still does not work.
Can someone tell me how to implement the propertyChanged
event for a custom property for updateting the datasource
in C#.

Thanks in advance
Eduard

.
 
Back
Top