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 Data Binding / November 2005

Tip: Looking for answers? Try searching our database.

DataBinding confusion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bg - 16 Nov 2005 12:25 GMT
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

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.