0

I am working in C# 4.5 - Winform. My question is specific to C# WinForm.

I want to bind a Control's property to another control's property value on the same form.

I have a GroupBox and a Check Box. When Check box is checked then group box should be enabled and when CheckBox in un-checked then GroupBox should be disabled. However this task can be fulfilled by implement checkbox "CheckedChanged" event. But i want to accomplish this without writing any code. I dont know it is possible or not. If possible then please provide solution. enter image description here

Haider Ali Wajihi
  • 2,756
  • 7
  • 51
  • 82

1 Answers1

3

It is possible to do via the designer. For your control -> Properties -> Binding...

But it is a lot of steps to result in a line of code in the designer file which you can add yourself just as easily in the constructor:

this.groupBox.DataBindings.Add( "Enabled", this.myCheckBox, "Checked" );
John Arlen
  • 6,539
  • 2
  • 33
  • 42
  • Thank you soo much. You actually determined what i was looking for. Thnx – Haider Ali Wajihi May 21 '14 at 04:32
  • I may be missing something. The designer method only allows you to bind a control's property to a data source. Unlike the coded version, which is way more flexible, allowing to bind the control's property to any object's property (optionally implementing the `INotifyPropertyChanged` interface, or PropertyChanged pattern). – Adam L. S. Apr 28 '21 at 14:54
  • While you are obviously correct that manually coding gives greater control, the designer method allows a lot more power than most realize. Through [Advanced] you can specify or create data sources on the fly from Types in the projects, etc. If you know enough to be comfortable manually handling that's great. – John Arlen Apr 29 '21 at 15:28