8
Answers

ComboBoxes and TextBox control visibility

Hind Najim

Hind Najim

11y
3k
1

Hello,,


I'm reposting this question again, hope to get solution soon.

For the below four comboBoxes implementation, I need to turn TextBox Visibility to true Only if I selected the Item = "ID" from any comboBox. This code works fine, but the the textbox will be invisible if I selected any other item from the other comboBoxes..


For example: If I selected "ID" from ComboBox2, then texBox will be visible beside comboBox2 (But I still need this to be visible  even if I select some other items from the other three comboBoxes

So, The textbox is invisible by default, and if "ID" is not selected from any comboBox, textbox will remain invisible. If it's being selected from any of comboBoxes, it will remain visible but only beside the comboBox.


Hope to check my code below and let me know what to add/change. I think a function will be a good idea so that I can call it in each comboBox



private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {if (comboBox1.SelectedItem == "ID")
            {
                TextBox1.Visible = true;
  TextBox1.Location = new System.Drawing.Point (31, 59);
            }
            else
            {
                TextBox1.Visible = false;
            }


private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {if (comboBox2.SelectedItem == "ID")
            {
                TextBox1.Visible = true;
  TextBox1.Location = new System.Drawing.Point (31, 91);
            }
            else
            {
                TextBox1.Visible = false;
            }

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {if (comboBox3.SelectedItem == "ID")
            {
                TextBox1.Visible = true;
  TextBox1.Location = new System.Drawing.Point (31, 122);
            }
            else
            {
                TextBox1.Visible = false;
            }


private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {if (comboBox4.SelectedItem == "ID")
            {
                TextBox1.Visible = true;
  TextBox1.Location = new System.Drawing.Point (31, 150);
            }
            else
            {
                TextBox1.Visible = false;
            }


Answers (8)