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#
help
8 Posts 4 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.
  • K Offline
    K Offline
    KakitaIppatsu
    wrote on last edited by
    #1

    I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.

    J B OriginalGriffO 3 Replies Last reply
    0
    • K KakitaIppatsu

      I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.

      J Offline
      J Offline
      John Torjo
      wrote on last edited by
      #2

      You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John

      -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

      K OriginalGriffO 2 Replies Last reply
      0
      • J John Torjo

        You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John

        -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

        K Offline
        K Offline
        KakitaIppatsu
        wrote on last edited by
        #3

        That removed the error, but introduced another. I now get an error on the same line but is is under FormA.PanelA stating: An object reference is required for the non-static field, method or property. txtQtyB.Text = FormA.panelA.txtQtyA.Text; I'm not sure how I can change the accessor for a dynamically created control? And just to add a little more. FormA creates and calls FormB.

        J 1 Reply Last reply
        0
        • K KakitaIppatsu

          That removed the error, but introduced another. I now get an error on the same line but is is under FormA.PanelA stating: An object reference is required for the non-static field, method or property. txtQtyB.Text = FormA.panelA.txtQtyA.Text; I'm not sure how I can change the accessor for a dynamically created control? And just to add a little more. FormA creates and calls FormB.

          J Offline
          J Offline
          John Torjo
          wrote on last edited by
          #4

          You need an instance of FormA, like:

          var forma = new FormA();
          txtQtyB.Text = forma.panelA.txtQtaA.Text;

          Or, more likely:

          var forma = new FormA();
          txtQtyB.Text = forma.txtQtaA.Text;

          -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

          OriginalGriffO 1 Reply Last reply
          0
          • K KakitaIppatsu

            I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            Changing the 'Ctor of a Form's access to 'Public is a mistake. You need to set up a dynamic linkage between the run-time created TextBoxes in FormA and FormB. There are several ways you could do this, all relatively simple to implement. One example: 1. if FormB is a "Main Form" and creates the instance of FormA, you could have code in FormB create the TextBoxes at run-time and inject them into FormA: that way, FormB would have direct references to the TextBoxes. To select from several other possible techniques, it would be helpful to know: 1. which is the "Main Form" here: A, B, or ? if A is not the Main Form where is the code that declares an instance of it and shows it ? 2. which is the Form in which the run-time TextBoxes in A are created: A ? or ? 3. do the number of TextBoxes created at run-time vary, or are they always the same number of TextBoxes ?

            «I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

            1 Reply Last reply
            0
            • J John Torjo

              You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John

              -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              No. This is a bad idea - it ties the two design of the two forms together and means they can't be modified without considering the impact of changes on the outside world. The default setting is private for a reason, and changing it to public is a hack!

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • K KakitaIppatsu

                I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                Bill is absolutely right - making the controls public is a bad mistake. This is a simple thing to do, and it's not difficult to manage correctly. Exactly how you do it depends on the "relationship" between the two forms, but one of these will cover it: Transferring information between two forms, Part 1: Parent to Child[^] Transferring information between two forms, Part 2: Child to Parent[^] Transferring information between two forms, Part 3: Child to Child[^] In all three, the "Parent" is the form that creates an instance of the "Child" via the new keyword.

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • J John Torjo

                  You need an instance of FormA, like:

                  var forma = new FormA();
                  txtQtyB.Text = forma.panelA.txtQtaA.Text;

                  Or, more likely:

                  var forma = new FormA();
                  txtQtyB.Text = forma.txtQtaA.Text;

                  -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  Or even more likely, he needs the existing instance of the form that the user entered data into... :sigh:

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  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