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. passing data between forms

passing data between forms

Scheduled Pinned Locked Moved C#
question
7 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.
  • M Offline
    M Offline
    mamoony
    wrote on last edited by
    #1

    Hi, I have a dll class and from here I am calling a form. I am able to send data from the dll class to the form. But how I am going to get data back from the form to the dll class? I wsed the same code but it is not working backward.

    frmLogin login = new frmLogin();

            login.Type = type;
            login.Username = username;
            login.Password = password;
            login.Group = group;
            
            login.ShowDialog();
    

    Thanks in advance, Sai

    Richard Andrew x64R OriginalGriffO 2 Replies Last reply
    0
    • M mamoony

      Hi, I have a dll class and from here I am calling a form. I am able to send data from the dll class to the form. But how I am going to get data back from the form to the dll class? I wsed the same code but it is not working backward.

      frmLogin login = new frmLogin();

              login.Type = type;
              login.Username = username;
              login.Password = password;
              login.Group = group;
              
              login.ShowDialog();
      

      Thanks in advance, Sai

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Why can't you simply reverse the assignments you have?

      login.ShowDialog();

      username = login.Username;
      password = login.Password;

      etc....

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • M mamoony

        Hi, I have a dll class and from here I am calling a form. I am able to send data from the dll class to the form. But how I am going to get data back from the form to the dll class? I wsed the same code but it is not working backward.

        frmLogin login = new frmLogin();

                login.Type = type;
                login.Username = username;
                login.Password = password;
                login.Group = group;
                
                login.ShowDialog();
        

        Thanks in advance, Sai

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

        Create a property (or several) in the Form and read it back from the instance once ShowDialog returns - it won't until the user closes the form, so read the data at that point.

                frmLogin login = new frmLogin();
                login.Type = type;
                login.Username = username;
                login.Password = password;
                login.Group = group;
                
                login.ShowDialog();
        
                type = login.Type;
                username = login.Username;
                password = login.Password;
                group = login.Group;
        

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "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

        M 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Create a property (or several) in the Form and read it back from the instance once ShowDialog returns - it won't until the user closes the form, so read the data at that point.

                  frmLogin login = new frmLogin();
                  login.Type = type;
                  login.Username = username;
                  login.Password = password;
                  login.Group = group;
                  
                  login.ShowDialog();
          
                  type = login.Type;
                  username = login.Username;
                  password = login.Password;
                  group = login.Group;
          

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          M Offline
          M Offline
          mamoony
          wrote on last edited by
          #4

          What I did.... In Class 1

          if (login.ShowDialog()== DialogResult.OK)
          {
          ans= login.Result;
          }

          In form 1

          public int Result
          {
          get;
          set;
          }

          Result = value;
          this.DialogResult = DialogResult.OK;

          Thnks a lot all, Sai

          OriginalGriffO B 2 Replies Last reply
          0
          • M mamoony

            What I did.... In Class 1

            if (login.ShowDialog()== DialogResult.OK)
            {
            ans= login.Result;
            }

            In form 1

            public int Result
            {
            get;
            set;
            }

            Result = value;
            this.DialogResult = DialogResult.OK;

            Thnks a lot all, Sai

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

            That'll do it! Nice one - well done.

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "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
            • M mamoony

              What I did.... In Class 1

              if (login.ShowDialog()== DialogResult.OK)
              {
              ans= login.Result;
              }

              In form 1

              public int Result
              {
              get;
              set;
              }

              Result = value;
              this.DialogResult = DialogResult.OK;

              Thnks a lot all, Sai

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

              I can't make any connection between the code you show here, and any other post on this thread: This code is not going to compile: 1. the variable 'ans is never declared, or used, just assigned to; will not compile. 2. the variable 'value is never declared: Result = value; will not compile. 3. the statement: "this.DialogResult = DialogResult.OK;" makes no sense unless you have a Form1 scoped variable with the name 'DialogResult declared, and, you should not use variable names identical to Operator names since that way lies utter code confusion. And why would you need a Form1 scoped variable of this type in the first place ? This is a case where posting code-fragments means no meaningful response is possible. best, Bill

              "If you shoot at mimes, should you use a silencer ?" Stephen Wright

              M 1 Reply Last reply
              0
              • B BillWoodruff

                I can't make any connection between the code you show here, and any other post on this thread: This code is not going to compile: 1. the variable 'ans is never declared, or used, just assigned to; will not compile. 2. the variable 'value is never declared: Result = value; will not compile. 3. the statement: "this.DialogResult = DialogResult.OK;" makes no sense unless you have a Form1 scoped variable with the name 'DialogResult declared, and, you should not use variable names identical to Operator names since that way lies utter code confusion. And why would you need a Form1 scoped variable of this type in the first place ? This is a case where posting code-fragments means no meaningful response is possible. best, Bill

                "If you shoot at mimes, should you use a silencer ?" Stephen Wright

                M Offline
                M Offline
                mamoony
                wrote on last edited by
                #7

                It compiled and worked. Thanks, Sai

                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