DataBinding problem

M

Martin

Hello,

i written a collection which holds instances of a specifc class. i added a
binding like that

textBox1.DataBindings.Add("Text", ((MyClass)oMyCollection[1],
"Description");

If the content of the textbox changed, the values are saved in the object of
the collection where the controls is bound to. my problem is that other
controls don't refresh their data. so if i change the value of a property in
my instance. the control still holds the old value. i tried the following:

this.BindingContext[((MyClass)oMyCollection[1],
"Description"].EndCurrentEdit();

but it wasn't the solution. any ideas?
 
B

Bart Mermuys

Hi,

Martin said:
Hello,

i written a collection which holds instances of a specifc class. i added a
binding like that

textBox1.DataBindings.Add("Text", ((MyClass)oMyCollection[1],
"Description");

You are binding to a single object which isn't a problem. But then your
"object" must have a <PropertyName>Changed event for each property, like:

public class MyClass
{
private string name;

public event EventHandler NameChanged;

public string Name
{
get
{
return name;
}
set
{
if ( name != value )
{
name = value;
if ( NameChanged != null )
NameChanged( this, EventArgs.Empty );
}
}
}
}


HTH,
Greetings



If the content of the textbox changed, the values are saved in the object
of the collection where the controls is bound to. my problem is that other
controls don't refresh their data. so if i change the value of a property
in my instance. the control still holds the old value. i tried the
following:

this.BindingContext[((MyClass)oMyCollection[1],
"Description"].EndCurrentEdit();

but it wasn't the solution. any ideas?
 
M

Martin

Thanks, now it works.


Bart Mermuys said:
Hi,

Martin said:
Hello,

i written a collection which holds instances of a specifc class. i added
a binding like that

textBox1.DataBindings.Add("Text", ((MyClass)oMyCollection[1],
"Description");

You are binding to a single object which isn't a problem. But then your
"object" must have a <PropertyName>Changed event for each property, like:

public class MyClass
{
private string name;

public event EventHandler NameChanged;

public string Name
{
get
{
return name;
}
set
{
if ( name != value )
{
name = value;
if ( NameChanged != null )
NameChanged( this, EventArgs.Empty );
}
}
}
}


HTH,
Greetings



If the content of the textbox changed, the values are saved in the object
of the collection where the controls is bound to. my problem is that
other controls don't refresh their data. so if i change the value of a
property in my instance. the control still holds the old value. i tried
the following:

this.BindingContext[((MyClass)oMyCollection[1],
"Description"].EndCurrentEdit();

but it wasn't the solution. any ideas?
 

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