Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Im my project, i have a requirement (rather small). Depending on the Checked/Unchecked state of check box, many other controls needs to be enabled/disabled.

For example take a check box and an edit control.

Programatically we can do it as :
textbox.Enabled = checkbox.Checked;

Can we make any settings in control's properties so that we need not handle them in our application?

Thanks in Advance
Posted
Comments
Xeshan Ahmed 20-Oct-11 12:32pm    
according to my knowledge it is not possible to directly bind
Xeshan Ahmed 20-Oct-11 12:33pm    
there is a way that on checked change event you can enable/disable all the controls
Wayne Gaylard 20-Oct-11 12:34pm    
Are you using WPF or WinForms ?
Xeshan Ahmed 20-Oct-11 12:38pm    
do share your code with us to get proper solution
[no name] 21-Oct-11 6:11am    
I am using WinForms

following code will enable/disable all controls of your active form on the basis of checked state of your checkbox
C#
private void cbxEnableControls_CheckedChanged(object sender, EventArgs e)
{
    EnableControls(cbxEnableControls.Checked);
}

private void EnableControls(bool Enable)
{
    foreach (Control c in this.Controls)
        c.Enabled = Enable;
}
 
Share this answer
 

You can use Binding.


You asked about DependencyProperty. So, you propably meant to a WPF solution.


Using WPF, you can set a name to your CheckBox, like the following:


XML
<CheckBox x:Name="cbEnableControls" Content="Enable controls"/>

and, bind the IsEnabled property to the IsChecked property of the CheckBox, like the following:


XML
<TextBox IsEnabled="{Binding IsChecked, ElementName=cbEnableControls}" />

But, the code example looks like WinForms. If you use Winforms, see the MSDN topic about the Binding class.

 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900