Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Moving data from one form to another

Moving data from one form to another

Scheduled Pinned Locked Moved C#
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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?

    R X 2 Replies Last reply
    0
    • L Lost User

      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?

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      There are several ways to do this. I'll give you the "easiest" (and least elegant):

      1. Make the Form1.myListBox member public.
      2. Pass a reference of the Form1 instance to Form2.
      3. In Form2's OnOKButtonClicked() handler, add the required entry to myListBox.

      /ravi

      My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com

      L 1 Reply Last reply
      0
      • L Lost User

        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?

        X Offline
        X Offline
        XeoN Kc
        wrote on last edited by
        #3

        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. ;)

        L 1 Reply Last reply
        0
        • X XeoN Kc

          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. ;)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yea... uhmm I'm still a little confused... do you have an example or a website with a tutorial?

          1 Reply Last reply
          0
          • R Ravi Bhavnani

            There are several ways to do this. I'll give you the "easiest" (and least elegant):

            1. Make the Form1.myListBox member public.
            2. Pass a reference of the Form1 instance to Form2.
            3. In Form2's OnOKButtonClicked() handler, add the required entry to myListBox.

            /ravi

            My new year resolution: 2048 x 1536 Home | Music | Articles | Freeware ravib(at)ravib(dot)com

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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.

            R 1 Reply Last reply
            0
            • L Lost User

              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.

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              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

              L 1 Reply Last reply
              0
              • R Ravi Bhavnani

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Yea i know.. I haven't continued, but I'm ordering two books and going to read some more.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups