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. How to get a value from other forms

How to get a value from other forms

Scheduled Pinned Locked Moved C#
tutorialhelpquestion
11 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.
  • N Offline
    N Offline
    Nine_
    wrote on last edited by
    #1

    Hi all Can anyone tell me how to get a value from other forms? For example, I have two forms on the project, Form1 and Form2. And I have a textbox and a button on Form1, when clicking the button, Form2 opened with a listbox on it. The problem is I want the selected item on the listbox shown in the textbox on Form1, can anyone hepl me this? Thankz advance:zzz::zzz:

    C 1 Reply Last reply
    0
    • N Nine_

      Hi all Can anyone tell me how to get a value from other forms? For example, I have two forms on the project, Form1 and Form2. And I have a textbox and a button on Form1, when clicking the button, Form2 opened with a listbox on it. The problem is I want the selected item on the listbox shown in the textbox on Form1, can anyone hepl me this? Thankz advance:zzz::zzz:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can expose values as properties, or pass them using delegates.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      N S 2 Replies Last reply
      0
      • C Christian Graus

        You can expose values as properties, or pass them using delegates.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        N Offline
        N Offline
        Nine_
        wrote on last edited by
        #3

        Can you give more explaination about how to do it with delegates? Thankz:rolleyes::rolleyes:

        C 1 Reply Last reply
        0
        • C Christian Graus

          You can expose values as properties, or pass them using delegates.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          How would you do this because I've had the same problem before and have had to find a less-than-perfect workaround. I don't think properties would work because the first form wont know when the selected index of the listbox on the second form has changed and therefore wont know when to update its textbox(unless you had a thread that continually checked). How would you use delegates to do it?

          There are 10 types of people in the world, those who understand binary and those who dont.

          C 1 Reply Last reply
          0
          • N Nine_

            Can you give more explaination about how to do it with delegates? Thankz:rolleyes::rolleyes:

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            This[^] should do it.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            1 Reply Last reply
            0
            • S ScottM1

              How would you do this because I've had the same problem before and have had to find a less-than-perfect workaround. I don't think properties would work because the first form wont know when the selected index of the listbox on the second form has changed and therefore wont know when to update its textbox(unless you had a thread that continually checked). How would you use delegates to do it?

              There are 10 types of people in the world, those who understand binary and those who dont.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              smyers wrote:

              I don't think properties would work because the first form wont know when the selected index of the listbox on the second form has changed and therefore wont know when to update its textbox(unless you had a thread that continually checked

              That's why you use delegates.

              smyers wrote:

              How would you use delegates to do it?

              Create a delegate that passes the value you want to broadcast, in the form with the control that changes. Hook this delegate to a method in the form that you want to inform of a changed value.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              N S 2 Replies Last reply
              0
              • C Christian Graus

                smyers wrote:

                I don't think properties would work because the first form wont know when the selected index of the listbox on the second form has changed and therefore wont know when to update its textbox(unless you had a thread that continually checked

                That's why you use delegates.

                smyers wrote:

                How would you use delegates to do it?

                Create a delegate that passes the value you want to broadcast, in the form with the control that changes. Hook this delegate to a method in the form that you want to inform of a changed value.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                N Offline
                N Offline
                Nine_
                wrote on last edited by
                #7

                So,delegates are the best answer?

                C S 2 Replies Last reply
                0
                • N Nine_

                  So,delegates are the best answer?

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Yes, almost always.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  N 1 Reply Last reply
                  0
                  • C Christian Graus

                    Yes, almost always.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                    N Offline
                    N Offline
                    Nine_
                    wrote on last edited by
                    #9

                    Thankz for quick reply

                    1 Reply Last reply
                    0
                    • N Nine_

                      So,delegates are the best answer?

                      S Offline
                      S Offline
                      ScottM1
                      wrote on last edited by
                      #10

                      They are the only answer

                      There are 10 types of people in the world, those who understand binary and those who dont.

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        smyers wrote:

                        I don't think properties would work because the first form wont know when the selected index of the listbox on the second form has changed and therefore wont know when to update its textbox(unless you had a thread that continually checked

                        That's why you use delegates.

                        smyers wrote:

                        How would you use delegates to do it?

                        Create a delegate that passes the value you want to broadcast, in the form with the control that changes. Hook this delegate to a method in the form that you want to inform of a changed value.

                        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                        S Offline
                        S Offline
                        ScottM1
                        wrote on last edited by
                        #11

                        Thanks, will try this out

                        There are 10 types of people in the world, those who understand binary and those who dont.

                        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