Databinding

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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)?
 
G

Guest

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

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top