30 October 2012

Pass TextBox Values into another form ComboBox in C#.net

Today ,we will discuss about Pass One control Value to another Form in C#.net. · Create a Project in VS 2008. · Create Two Form .Form 1 and Form2. · Create TextBoxes and One Button on Form1. · Rename name the TextBox .Start with txt. · Create ComboBox on Form2. Now , we will go to Our scenario. Copy and Paste the following codes in Form 1 Code View Section
public static string[] textvalues; List values = new List(); private void button1_Click(object sender, EventArgs e) { foreach (Control con in this.Controls) { if (con.Name.StartsWith("txt")) { values.Add(con.Text); } } textvalues = values.ToArray(); Form2 frm = new Form2(); frm.Show(); }
Copy and Paste the following codes in Form 2 Code View Section
private void Form2_Load(object sender, EventArgs e) { comboBox1.Items.Clear(); foreach (string str in Form1.textvalues) { comboBox1.Items.Add(str); } }
Just Run the Application and Enter the values and click Button1 .

No comments: