Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two form .form1 has a listbox. and form2 has a textbox and a button.if i write my name in textbox and click to add button then my name should add in list box.
Posted
Comments
Daniele Rota Nodari 27-Nov-12 5:20am    
Is there any reference between the two forms? Is one of them the parent or owner of the other? Are their references stored somewhere?
In case none of this conditions are met You can use Application.OpenForms to find a reference to form1.

Then, if listbox is private (or protected) You should make it public (or internal) or add into form1 some method or property to forward access to it, or to its properties.
Mohd. Mukhtar 27-Nov-12 5:45am    
What have you tried to do the same?

1 solution

Hi
Can you try this.

C#
 Form1.cs

  Form2 f2 = new Form2();
  f2.ShowDialog();

 public  void UpdateListBox(string lstValue)
 {
   listBox1.Items.Add(lstValue);
 }

 Form2.cs
  
  Form1 f1= (Form1)Application.OpenForms["Form1"];
  f1.UpdateListBox(textBox1.Text);
 
Share this answer
 
Comments
Dominic Abraham 27-Nov-12 7:29am    
Your issue got solved?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900