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 / September 2007

Tip: Looking for answers? Try searching our database.

binding CheckBox.Enabled to ComboBox selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jiho Han - 21 Sep 2007 15:56 GMT
I have a combo which is bound to a List<MyCustomObject>.
One of the properties of MyCustomObject is a boolean which I would like to
bind to a checkbox so that depending on the selection on the combobox, the
checkbox below it would get enabled/disabled accordingly.

How can this be achieved through databinding?  I don't want to implement
this through any event handling - just pure databinding.

My initial effort was this:
checkbox.DataBindings.Add("Enabled", combobox,
"SelectedItem.MyBooleanProperty");

However, the above code does not work.
Thanks
Juanma Mtnez - 27 Sep 2007 14:36 GMT
Hi, Jiho:

In theory, to bind an object member to another, the first must implement
IListSource interface.

If you want to bind the contents of your generic List<MyCustomObject>, you
should ensure that it implements that, so maybe it would be better to use
another kind of collection instead List<>. Try to use, for example, a custom
collection that implements IList<> as well as IListSource.

Kind regards

> I have a combo which is bound to a List<MyCustomObject>.
> One of the properties of MyCustomObject is a boolean which I would like to
[quoted text clipped - 10 lines]
> However, the above code does not work.
> Thanks
Jiho Han - 27 Sep 2007 15:07 GMT
Thanks for your response.  But I am still a bit confused.

I have other controls such as checkboxes and texboxes that are bound to a
custom object, a plain object that doesn't implement any interfaces
whatsoever.

And I am able to bind using, for example:

OnCheckbox.DataBindings.Add("Checked", myCustomObject, "On");

So in essence, my original problem is same except that at the time of this
binding setup, the object is not available because that object would be
selected by the combo.  The combo's SelectedItem property would return
another plain object and I am trying to bind to one of its properties to this
checkbox.  It's basically cascade (or nested) binding, like master-detail
(which I searched for and all I got was using two datagrids)

> Hi, Jiho:
>
[quoted text clipped - 22 lines]
> > However, the above code does not work.
> > Thanks
Juanma Mtnez - 28 Sep 2007 14:35 GMT
Hi again, Jiho:

I've been trying to solve the problem and I think I've found a solution. If
you bind the control (combo) to the other (checkbox) It doesn't work because,
as it seems, combobox doesn't implement IListSource.

Anyway, try to bind the CheckBox to the List<MyCustomObject> object. I did
it and it worked.

Here is the code portion I wrote to prove it:

           List<MyCustomObject> collection = new List<MyCustomObject>();
           collection.Add(new MyCustomObject());
           MyCustomObject obj2 = new MyCustomObject();
           obj2.BooleanProperty = true;
           comboBox1.DataSource = collection;
           collection.Add(obj2);
           comboBox1.DisplayMember = "BooleanProperty";

           Binding binding = new Binding("Checked", collection,
"BooleanProperty");
           this.checkBox1.DataBindings.Add(binding);

Assuming that BooleanProperty is false by default at the above code.

I hope this time you got the correct answer.

Regards.

> Thanks for your response.  But I am still a bit confused.
>
[quoted text clipped - 39 lines]
> > > However, the above code does not work.
> > > Thanks

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.