I made a simple winforms application to help you with this problem.
Here is the Interface of the Application
Application IMAGE
Here are the names that I used for the controls that I used in the code
Application Control Names IMAGE
You can disable GB_2 and GB_3 when the form loads by using the following code in the form Load event.
private void Form_Load(object sender, EventArgs e)
{
GB_2.Enabled = false;
GB_3.Enabled = false;
}
At Runtime (As soon as the form loads)
Runtime IMAGE
Scenario 1
By Selecting "Enabled or Disabled" from the Combo Boxes in GB_1, The User can Enable or Disable GB_2 or GB_3.
This is done by using the SelectedIndexChanged event for a combo box
Cmb_GB1_1 and Cmb_GB1_2 Have similar items as follows
- Item 01 : Disabled
- Item 02 : Enabled
The Code Behind Cmb_GB1_1 and Cmb_GB1_2
private void Cmb_1_SelectedIndexChanged(object sender, EventArgs e)
{
if (Cmb_GB1_1.SelectedIndex <=0)
{
GB_2.Enabled = false;
}
else
{
GB_2.Enabled = true;
}
}
private void Cmb_2_SelectedIndexChanged(object sender, EventArgs e)
{
if (Cmb_GB1_2.SelectedIndex <= 0)
{
GB_3.Enabled = false;
}
else
{
GB_3.Enabled = true;
}
Scenario 2
Here GB_2 and GB_3 are only enabled when the text in all three Combo Boxes are not equal to "False"
This is done by using the SelectedIndexChanged event for a combo box
Cmb_GB4_1 , Cmb_GB4_2 and Cmb_GB4_3 Have similar items as follows
- Item 01 : False
- Item 02 : Active
- Item 02 : OK
The Code Behind Cmb_GB4_1 , Cmb_GB4_2 and Cmb_GB4_3
private void Cmb_GB4_1_SelectedIndexChanged(object sender, EventArgs e)
{
Enb_Dis_GB();
GB_1_TEXT_CHANGER();
}
private void Cmb_GB4_2_SelectedIndexChanged(object sender, EventArgs e)
{
Enb_Dis_GB();
GB_1_TEXT_CHANGER();
}
private void Cmb_GB4_3_SelectedIndexChanged(object sender, EventArgs e)
{
Enb_Dis_GB();
GB_1_TEXT_CHANGER();
}
I created two methods
- Enb_Dis_GB() : To Enable Both GB_2 and GB_3 when none of the 3 combo Boxes have "False"
- GB_1_TEXT_CHANGER() : This Changes the text in Cmb_GB1_1 and Cmb_GB1_2 as necessary
The Code Behind
Enb_Dis_GB()
private void Enb_Dis_GB()
{
if (Cmb_GB4_1.SelectedIndex > 0 && Cmb_GB4_2.SelectedIndex > 0 && Cmb_GB4_3.SelectedIndex > 0)
{
GB_2.Enabled = true;
GB_3.Enabled = true;
}
else
{
GB_2.Enabled = false;
GB_3.Enabled = false;
}
}
GB_1_TEXT_CHANGER()
private void GB_1_TEXT_CHANGER()
{
if(Cmb_GB4_1.SelectedIndex > 0 && Cmb_GB4_2.SelectedIndex > 0 && Cmb_GB4_3.SelectedIndex > 0)
{
Cmb_GB1_1.Text = "Enabled";
Cmb_GB1_2.Text = "Enabled";
}
else
{
Cmb_GB1_1.Text = "Disabled";
Cmb_GB1_2.Text = "Disabled";
}
}
A Set of images Showing the program At runtime.
Scenario 1 IMAGE
Scenario 2 Case 1 IMAGE
Scenario 2 Case 2 IMAGE