Lets do something more with the previous tutorial. Open up the previous WindowsControlsTutorials solution.
- Add a comboBox from the toolbox to the Form.
- Change the Text Property of the button from Show to Add.
- Double click on the button and write this comboBox1.Items.Add(textBox1.Text + " " + textBox2.Text + " " + textBox3.Text); MessageBox.Show("Name Added");
- The first line will add a item in the comboBox1 with the given values in the textBox's. The second line will show a notification through a messageBox that a name has been added successfully in the comboBox.
- Go back to Form1.cs[Design] tab and double click on the comboBox.
- this will generate the event private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {}
- Write down MessageBox.Show(comboBox1.Text); in the curly braces.
- Start Debugging.
- Give values and press Add.
- This will enter a item in the comboBox with the given text in the textBox's.
- Add as many names as you like.
- Now select a item from the comboBox.
- A messageBox will popup and show the Text of the comboBox selected index.
- In this tutorial when you cahnge the comboBox selected index the comboBox1_SelectedIndexChanged event fires up and show the index item Text in the messageBox.
No comments:
Post a Comment