Click here to Skip to main content
15,914,322 members
Articles / Programming Languages / C#
Tip/Trick

Populating Multiple Text Boxes From A Single Combo Box And Two Buttons

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
28 Sep 2011CPOL 7.8K   1   2
Easy Recipe

  1. Create a winform application
  2. add two text boxes
  3. add one combo box
  4. add two buttons

Step One: Give the combo box a few values (ex: Car, Truck and Motorcycle)

Step Two: Code The button1 click event. Double click on button1 to create the button1 click event. You should see the following

C#
private void button1_Click(object sender, EventArgs e)
        {

        }

Now code the button1 event with
C#
private void button1_Click(object sender, EventArgs e)
        {
          //  Note Target = Source
            // textbox1 is your target and combobox1 is your source
            textBox1.Text = comboBox1.Text;
        }

Step Three: Code the button2 click event. Double click on button2 to create the button2 click event. You should see the following
C#
private void button2_Click(object sender, EventArgs e)
       {

       }

Now code the button 2 event with
C#
private void button2_Click(object sender, EventArgs e)
      {
          //  Note Target = Source
          // textbox2 is your target and combobox1 is your source
          textBox2.Text = comboBox1.Text;
      }

Now take her for a spin. Click on your combo box and select a value. Once your value has been selected, click on button 1 to populate the textbox1. Click on your combo box and choose another value. Once your value has been selected, click on button 2 to populate texbox2.

This technique makes it easy for users to fill in multiple text boxes from a single combo box stuffed with preset values.

License

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


Written By
Software Developer (Senior) Lakeland Open MRI
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 1 very bad Pin
knoami1-Oct-11 0:02
knoami1-Oct-11 0:02 
Reason for my vote of 1
very bad
GeneralRe: I am a brand new, did i do something wrong? Pin
DataBlue14-Oct-11 4:33
DataBlue14-Oct-11 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.