Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Trying to bind to Visible or Enabled property of form control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sam Martin - 16 Aug 2005 12:15 GMT
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?

Signature

TIA
Sam Martin

Bart Mermuys - 16 Aug 2005 13:36 GMT
Hi,

> Hi,
>
[quoted text clipped - 17 lines]
> 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?
Sam Martin - 16 Aug 2005 14:36 GMT
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??

Signature

TIA
Sam Martin

> Hi,
>
[quoted text clipped - 51 lines]
>
> > how do I do it?
Bart Mermuys - 16 Aug 2005 15:56 GMT
Hi,

> 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");
>
[quoted text clipped - 10 lines]
> }
> }

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??
>
[quoted text clipped - 55 lines]
>>
>> > how do I do it?
Sam Martin - 16 Aug 2005 16:43 GMT
thank for your help mate

Signature

TIA
Sam Martin

> Hi,
>
[quoted text clipped - 95 lines]
> >>
> >> > how do I do it?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.