hi all,
I'm trying to do some very simple databinding, with a buttons enabled
property and a custom class and i'm a bit confused.
I have this:
class Model
{
void BindGoButton(Button b)
{
b.DataBindings.Add(Enabled,this,"ShowGoButton");
}
public bool ShowGoButton
{
get
{
return _show;
}
}
..... // at some point throw an event telling the main form to update its
controls
};
in my form i'm just doing this
public MainForm()
{
_model.BindGoButton(button1);
}
My Question is this:
At some point in my Model class I want the form to update its controls, I
can do this by an event, but I can't work out what magic is needed to get
the button to update itself. The docs say I should use the forms
CurrencyManager and call refresh, but I can't work out how to get it.
if I use this from the form :
CurrencyManager cm = button1.BindContext[_model] as CurrencyManager
cm.Refresh();
but what I actually get back is a PropertyManager which doesn't have a
Refresh method;
So what can I call to get a form to do an "automatic" refesh of any controls
that may be databound?
TIA
bg
Michel Perfetti - 16 Nov 2005 12:43 GMT
Hello,
Do you not need a event in your form: you have to add a event ShowGoButtonChanged(
like that"public event EventHandler ShowGoButtonChanged" ) in your Model
class and call it when the value changed.
Every control bound to your property will be notified that your value changed.
--
Miiitch
> hi all,
>
[quoted text clipped - 48 lines]
>
> bg
Bart Mermuys - 16 Nov 2005 13:00 GMT
Hi,
> hi all,
>
[quoted text clipped - 44 lines]
> So what can I call to get a form to do an "automatic" refesh of any
> controls that may be databound?
If you want an automatic refresh, then you have to add an xxxChanged event
where xxx is the name of the property:
class Model
{
void BindGoButton(Button b)
{
b.DataBindings.Add(Enabled,this,"ShowGoButton");
}
public event EventHandler ShowGoButtonChanged;
public bool ShowGoButton
{
get { return _show; }
set
{
_show = value;
if ( ShowGoButtonChanged!=null )
ShowGoButtonChanged( this, EventArgs.Empty );
}
}
}
HTH,
Greetings
> TIA
>
> bg
bg - 16 Nov 2005 13:40 GMT
ok that works, thanks. Adding the event does indeed cause "magic" to happen
and the button appears Enabled correctly. But doing that means I end up with
an empty event handler in my form code - I don't need it to do anything, i
just want the button to enable/disable - seems very messy.
> class Model
> {
[quoted text clipped - 16 lines]
> }
> }
bg
bg - 16 Nov 2005 13:52 GMT
my mistake, you don't need to instiate the event just have one defined.
> ok that works, thanks. Adding the event does indeed cause "magic" to
> happen and the button appears Enabled correctly. But doing that means I
[quoted text clipped - 23 lines]
>
> bg