MatthijsFontys

Load combobox in second form

Dec 14th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. // Vervang Form2 door de naam van het andere form
  2. // Vervang comboBox1 door de naam van je combobox in het tweede form
  3.     public partial class Form1 : Form {
  4.         Form2 mySecondForm;
  5.         public Form1() {
  6.             InitializeComponent();
  7.             mySecondForm = new Form2();
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e) {
  11.             string username = textBox1.Text;
  12.             ComboBox cmboBox = ((ComboBox)mySecondForm.Controls.Find("comboBox1", true).FirstOrDefault());
  13.             cmboBox.Items.Add(username);
  14.         }
  15.  
  16.         private void button2_Click(object sender, EventArgs e) {
  17.             mySecondForm.Show();
  18.             this.Hide();
  19.  
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment