Hi,

just a quick one.
i'm trying to bind the Visible property of a control to a public property of
the parent form.
i.e.
private bool _okToDoSomething = false;

public bool IsOkToDoSometing {
get { return this._okToDoSomething; }
}

/// then in initialisation
this.buttonDoSomething.DataBindings.Add("Enabled",this, "IsOkToDoSomething");

i've read that binding can only occur if bound object implement IList (which
the form obviously doesn't) - so is something like this possible? and if so
how do I do it?

--
TIA
Sam Martin

Re: Trying to bind to Visible or Enabled property of form control by Bart

Bart
Tue Aug 16 07:36:50 CDT 2005

Hi,

"Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
news:4E3A9169-1F1A-4D10-A38A-08CA73B6BD5B@microsoft.com...
> Hi,
>
> just a quick one.
> i'm trying to bind the Visible property of a control to a public property
> of
> the parent form.
> i.e.
> private bool _okToDoSomething = false;
>
> public bool IsOkToDoSometing {
> get { return this._okToDoSomething; }
> }
>
> /// then in initialisation
> this.buttonDoSomething.DataBindings.Add("Enabled",this,
> "IsOkToDoSomething");
>
> i've read that binding can only occur if bound object implement IList
> (which
> the form obviously doesn't) - so is something like this possible? and if
> so

Well, binding of lists obvious need to implement IList (or at least
IListSource), but you can also bind to any property of any object.

You do need to add an event (propertyname + 'Changed'), so that bound
control(s) know when the property has changed, eg:

public event IsOkToDoSomethingChanged;

public bool IsOkToDoSometing
{
get { return this._okToDoSomething; }
set
{
_okToDoSomething = value;

// fire event
if ( IsOkToDoSomethingChanged!=null )
IsOkToDoSomething( this, EventArgs.Empty );
}
}

// then in initialisation
this.buttonDoSomething.DataBindings.Add("Enabled",this,
"IsOkToDoSomething");

Now you can use IsOkToDoSometing property to toggle button enabled state.


HTH,
Greetings


> how do I do it?
>
> --
> TIA
> Sam Martin



Re: Trying to bind to Visible or Enabled property of form control by sambomartin

sambomartin
Tue Aug 16 08:36:02 CDT 2005

hi bart, thanks for that

however, i've done as you said but the bindings are being updated.
when i step through a call to the IsNewAgreementCreated_set, the event is
not handled and is <undefined value>.

the binding is done after the call to InitialiseComponent.

this.newAgreementPanel.DataBindings.Add("Visible",this,"IsNewAgreementCreated");

public event EventHandler IsNewAgreementCreatedChanged;
public bool IsNewAgreementCreated
{
get { return this._createdAgreement; }
set
{
this._createdAgreement = value;

if (IsNewAgreementCreatedChanged!=null)
IsNewAgreementCreatedChanged(this,EventArgs.Empty);
}
}

is there anything else i need to do??

--
TIA
Sam Martin


"Bart Mermuys" wrote:

> Hi,
>
> "Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
> news:4E3A9169-1F1A-4D10-A38A-08CA73B6BD5B@microsoft.com...
> > Hi,
> >
> > just a quick one.
> > i'm trying to bind the Visible property of a control to a public property
> > of
> > the parent form.
> > i.e.
> > private bool _okToDoSomething = false;
> >
> > public bool IsOkToDoSometing {
> > get { return this._okToDoSomething; }
> > }
> >
> > /// then in initialisation
> > this.buttonDoSomething.DataBindings.Add("Enabled",this,
> > "IsOkToDoSomething");
> >
> > i've read that binding can only occur if bound object implement IList
> > (which
> > the form obviously doesn't) - so is something like this possible? and if
> > so
>
> Well, binding of lists obvious need to implement IList (or at least
> IListSource), but you can also bind to any property of any object.
>
> You do need to add an event (propertyname + 'Changed'), so that bound
> control(s) know when the property has changed, eg:
>
> public event IsOkToDoSomethingChanged;
>
> public bool IsOkToDoSometing
> {
> get { return this._okToDoSomething; }
> set
> {
> _okToDoSomething = value;
>
> // fire event
> if ( IsOkToDoSomethingChanged!=null )
> IsOkToDoSomething( this, EventArgs.Empty );
> }
> }
>
> // then in initialisation
> this.buttonDoSomething.DataBindings.Add("Enabled",this,
> "IsOkToDoSomething");
>
> Now you can use IsOkToDoSometing property to toggle button enabled state.
>
>
> HTH,
> Greetings
>
>
> > how do I do it?
> >
> > --
> > TIA
> > Sam Martin
>
>
>

Re: Trying to bind to Visible or Enabled property of form control by Bart

Bart
Tue Aug 16 09:56:30 CDT 2005

Hi,

"Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
news:616679C2-900E-4CB7-B57A-1C1B077BDF12@microsoft.com...
> hi bart, thanks for that
>
> however, i've done as you said but the bindings are being updated.

I guess you mean aren't updated .

> when i step through a call to the IsNewAgreementCreated_set, the event is
> not handled and is <undefined value>.

If you set IsNewAgreementCreated after binding, then the event shouldn't be
<undefined value>, so something isn't working.

>
> the binding is done after the call to InitialiseComponent.

That shouldn't be a problem.

>
> this.newAgreementPanel.DataBindings.Add("Visible",this,"IsNewAgreementCreated");
>
> public event EventHandler IsNewAgreementCreatedChanged;
> public bool IsNewAgreementCreated
> {
> get { return this._createdAgreement; }
> set
> {
> this._createdAgreement = value;
>
> if (IsNewAgreementCreatedChanged!=null)
> IsNewAgreementCreatedChanged(this,EventArgs.Empty);
> }
> }

I have copy/pasted the above code and added the private variable
_createdAgreement and a panel and it works perfectly (using net 1.1 vc2003).
I have no idea why it doesn't for you, maybe something's different but it's
not in the posted code.

Greetings

>
> is there anything else i need to do??
>
> --
> TIA
> Sam Martin
>
>
> "Bart Mermuys" wrote:
>
>> Hi,
>>
>> "Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
>> news:4E3A9169-1F1A-4D10-A38A-08CA73B6BD5B@microsoft.com...
>> > Hi,
>> >
>> > just a quick one.
>> > i'm trying to bind the Visible property of a control to a public
>> > property
>> > of
>> > the parent form.
>> > i.e.
>> > private bool _okToDoSomething = false;
>> >
>> > public bool IsOkToDoSometing {
>> > get { return this._okToDoSomething; }
>> > }
>> >
>> > /// then in initialisation
>> > this.buttonDoSomething.DataBindings.Add("Enabled",this,
>> > "IsOkToDoSomething");
>> >
>> > i've read that binding can only occur if bound object implement IList
>> > (which
>> > the form obviously doesn't) - so is something like this possible? and
>> > if
>> > so
>>
>> Well, binding of lists obvious need to implement IList (or at least
>> IListSource), but you can also bind to any property of any object.
>>
>> You do need to add an event (propertyname + 'Changed'), so that bound
>> control(s) know when the property has changed, eg:
>>
>> public event IsOkToDoSomethingChanged;
>>
>> public bool IsOkToDoSometing
>> {
>> get { return this._okToDoSomething; }
>> set
>> {
>> _okToDoSomething = value;
>>
>> // fire event
>> if ( IsOkToDoSomethingChanged!=null )
>> IsOkToDoSomething( this, EventArgs.Empty );
>> }
>> }
>>
>> // then in initialisation
>> this.buttonDoSomething.DataBindings.Add("Enabled",this,
>> "IsOkToDoSomething");
>>
>> Now you can use IsOkToDoSometing property to toggle button enabled state.
>>
>>
>> HTH,
>> Greetings
>>
>>
>> > how do I do it?
>> >
>> > --
>> > TIA
>> > Sam Martin
>>
>>
>>



Re: Trying to bind to Visible or Enabled property of form control by sambomartin

sambomartin
Tue Aug 16 10:43:37 CDT 2005


thank for your help mate

--
TIA
Sam Martin


"Bart Mermuys" wrote:

> Hi,
>
> "Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
> news:616679C2-900E-4CB7-B57A-1C1B077BDF12@microsoft.com...
> > hi bart, thanks for that
> >
> > however, i've done as you said but the bindings are being updated.
>
> I guess you mean aren't updated .
>
> > when i step through a call to the IsNewAgreementCreated_set, the event is
> > not handled and is <undefined value>.
>
> If you set IsNewAgreementCreated after binding, then the event shouldn't be
> <undefined value>, so something isn't working.
>
> >
> > the binding is done after the call to InitialiseComponent.
>
> That shouldn't be a problem.
>
> >
> > this.newAgreementPanel.DataBindings.Add("Visible",this,"IsNewAgreementCreated");
> >
> > public event EventHandler IsNewAgreementCreatedChanged;
> > public bool IsNewAgreementCreated
> > {
> > get { return this._createdAgreement; }
> > set
> > {
> > this._createdAgreement = value;
> >
> > if (IsNewAgreementCreatedChanged!=null)
> > IsNewAgreementCreatedChanged(this,EventArgs.Empty);
> > }
> > }
>
> I have copy/pasted the above code and added the private variable
> _createdAgreement and a panel and it works perfectly (using net 1.1 vc2003).
> I have no idea why it doesn't for you, maybe something's different but it's
> not in the posted code.
>
> Greetings
>
> >
> > is there anything else i need to do??
> >
> > --
> > TIA
> > Sam Martin
> >
> >
> > "Bart Mermuys" wrote:
> >
> >> Hi,
> >>
> >> "Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
> >> news:4E3A9169-1F1A-4D10-A38A-08CA73B6BD5B@microsoft.com...
> >> > Hi,
> >> >
> >> > just a quick one.
> >> > i'm trying to bind the Visible property of a control to a public
> >> > property
> >> > of
> >> > the parent form.
> >> > i.e.
> >> > private bool _okToDoSomething = false;
> >> >
> >> > public bool IsOkToDoSometing {
> >> > get { return this._okToDoSomething; }
> >> > }
> >> >
> >> > /// then in initialisation
> >> > this.buttonDoSomething.DataBindings.Add("Enabled",this,
> >> > "IsOkToDoSomething");
> >> >
> >> > i've read that binding can only occur if bound object implement IList
> >> > (which
> >> > the form obviously doesn't) - so is something like this possible? and
> >> > if
> >> > so
> >>
> >> Well, binding of lists obvious need to implement IList (or at least
> >> IListSource), but you can also bind to any property of any object.
> >>
> >> You do need to add an event (propertyname + 'Changed'), so that bound
> >> control(s) know when the property has changed, eg:
> >>
> >> public event IsOkToDoSomethingChanged;
> >>
> >> public bool IsOkToDoSometing
> >> {
> >> get { return this._okToDoSomething; }
> >> set
> >> {
> >> _okToDoSomething = value;
> >>
> >> // fire event
> >> if ( IsOkToDoSomethingChanged!=null )
> >> IsOkToDoSomething( this, EventArgs.Empty );
> >> }
> >> }
> >>
> >> // then in initialisation
> >> this.buttonDoSomething.DataBindings.Add("Enabled",this,
> >> "IsOkToDoSomething");
> >>
> >> Now you can use IsOkToDoSometing property to toggle button enabled state.
> >>
> >>
> >> HTH,
> >> Greetings
> >>
> >>
> >> > how do I do it?
> >> >
> >> > --
> >> > TIA
> >> > Sam Martin
> >>
> >>
> >>
>
>
>