Moving data from one form to another
-
Lets say I have two forms (Form1 and Form2). On Form1 there is a listbox that holds phone numbers. On Form2 there is two textboxes where you enter a phonenumber and a description. On Form1 you click a button and it opens Form2 to enter the information. So how do you take the information that is entered on Form2 and add it to the listbox on Form1?
-
Lets say I have two forms (Form1 and Form2). On Form1 there is a listbox that holds phone numbers. On Form2 there is two textboxes where you enter a phonenumber and a description. On Form1 you click a button and it opens Form2 to enter the information. So how do you take the information that is entered on Form2 and add it to the listbox on Form1?
There are several ways to do this. I'll give you the "easiest" (and least elegant):
- Make the
Form1.myListBox
member public. - Pass a reference of the
Form1
instance toForm2
. - In
Form2
'sOnOKButtonClicked()
handler, add the required entry tomyListBox
.
/ravi
My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com
- Make the
-
Lets say I have two forms (Form1 and Form2). On Form1 there is a listbox that holds phone numbers. On Form2 there is two textboxes where you enter a phonenumber and a description. On Form1 you click a button and it opens Form2 to enter the information. So how do you take the information that is entered on Form2 and add it to the listbox on Form1?
You can use Ravi's solution. However, that will make some data off your listbox, public. I suggest to have Form2 with a property of type string,which gets and sets the data. in your case the set is mostly important. From Form1...you only need to set the property. From form2 just set the given value to the textbox. I think its a little safer. Regards Kev. ;)
-
You can use Ravi's solution. However, that will make some data off your listbox, public. I suggest to have Form2 with a property of type string,which gets and sets the data. in your case the set is mostly important. From Form1...you only need to set the property. From form2 just set the given value to the textbox. I think its a little safer. Regards Kev. ;)
-
There are several ways to do this. I'll give you the "easiest" (and least elegant):
- Make the
Form1.myListBox
member public. - Pass a reference of the
Form1
instance toForm2
. - In
Form2
'sOnOKButtonClicked()
handler, add the required entry tomyListBox
.
/ravi
My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com
- Make the
-
I'm still lost on this. I made listBox1 public. Now how exactly am I going to do this? I need to transfer a textbox from Form2 back to Form1.
Jacob Dixon wrote:
I need to transfer a textbox from Form2 back to Form1.
No. You need to copy data from one control (a textbox) to another (a listbox). For example:
theListBox.Items.Add (theTextBox.Text);
It seems you may have taken on a task that's (currently) a bit out of your reach. I recommend that you come up to speed on the basics of WinForms before continuing. /ravi
My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com
-
Jacob Dixon wrote:
I need to transfer a textbox from Form2 back to Form1.
No. You need to copy data from one control (a textbox) to another (a listbox). For example:
theListBox.Items.Add (theTextBox.Text);
It seems you may have taken on a task that's (currently) a bit out of your reach. I recommend that you come up to speed on the basics of WinForms before continuing. /ravi
My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com