Hind Najim

Hind Najim

  • NA
  • 32
  • 18.2k

Show & Hide a textBox in different location

Sep 9 2013 1:18 PM

Hello,,

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 (2)