DataBinding problem

  • Thread starter Thread starter Martin
  • Start date Start date
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?
 
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?
 
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?
 
Back
Top