Search code examples
c#comboboxtextboxappend

in C#, Append selection multiple times from 2 ComboBoxes into a TextBox using a button


I am trying to append selections from 2 ComboBoxes into a TextBox with a click of a button and I am not sure how to do this. I can do it once with code like this:

 private void BTN_APPEND_Click(object sender, EventArgs e)
    {
        TB_CONNECTORS.Text = CB_PORT_NUMBER.Text + " " + CB_CONNECTOR.Text;
    }

And this will result in Append with the click of a button

but the question is, how can I append to this one more time?


Solution

  • Did you try this :

     if(!TB_CONNECTORS.Text == "")
     {
     TB_CONNECTORS.Text = TB_CONNECTORS.Text + " & " + CB_PORT_NUMBER.Text + " " + CB_CONNECTOR.Text;
     }
     else
     {
     TB_CONNECTORS.Text = CB_PORT_NUMBER.Text + " " + CB_CONNECTOR.Text;
     }
    

    This will result in the new value achieved from the 2 comboboxes keeping the existing text of the textbox