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 List to form and back... Help plz.

Passing List to form and back... Help plz.

Scheduled Pinned Locked Moved C#
helptutorialquestion
15 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.
  • C Christian Graus

    JollyMansArt wrote:

    but I am not understanding an example where I can pass List between parrent and child forms...

    DON'T pass a list control between your forms. Pass the list itself ( I don't know if that's what you mean by list ). Pass it into the form, then if the form is modal, you can just access it back out with a property. If the form is modeless, a delegate is needed to tell the main form when data was changed inside the other form ( assuming this is possible )

    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

    J Offline
    J Offline
    JollyMansArt
    wrote on last edited by
    #6

    I am not passing a control I am passing a List ABC Object which is sort of like string[].tolist() I agree with what your saying and I just thought of that to. Now I just have to remember how to do that. I have avoided interform communication methods in the past. Now it is time to figure out how to do it again. Your right though.. Encapsulating the new form in a using statement in a previous project did allow me to communicate with it from the parrent form. I just forget how to do that. I will research. Unless you have a sample. I am close in my code example i think.

    1 Reply Last reply
    0
    • J JollyMansArt

      I am sort of stumpped. I have a List EmailsTO List EmailsCC I want to be able to pass the lists into a form. Modify those lists in the form. Then return the new lists back to the Parrent form, followed by closing of the child form I am simulating as a popup. I can not figure out how to get the list ... into the form and back out. Can someone help point me in the right direction? Here is some of what I have come up with....

      using (frmpopupEmailRecipient popupVerifyEmailRecipients = new frmpopupEmailRecipient(ref EmailTo, ref EmailCC))
      {
      // passing this in ShowDialog will set the .Owner
      // property of the child form
      popupVerifyEmailRecipients.ShowDialog(this);
      }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #7

      Hi, I assume this is about System.Net.Mail.MailMessage, which has three properties (To, Cc, Bcc) of type MailAddressCollection. you can pass such lists just like any other object, and it does not need a ref keyword; and the receiving method can enumerate, add, remove, and perform all operations that the list supports. The one thing you cannot do is replace the list by a different list (that is the only operation that would require you to use the ref keyword). :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


      J 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I assume this is about System.Net.Mail.MailMessage, which has three properties (To, Cc, Bcc) of type MailAddressCollection. you can pass such lists just like any other object, and it does not need a ref keyword; and the receiving method can enumerate, add, remove, and perform all operations that the list supports. The one thing you cannot do is replace the list by a different list (that is the only operation that would require you to use the ref keyword). :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


        J Offline
        J Offline
        JollyMansArt
        wrote on last edited by
        #8

        Partial assumption is correct..... This is the mailmessage as to what it will go to. That part of the application I have working. I am tweaking the (to,cc,bc) before I pass the parameter to the procedure handling the list. To allow for the ability for a popup window with 2 checkbox list boxes. To allow the end user to override or add to the list of email addresses the will be used to send the autogenerated email. It was a requirement being asked in the last second. So I need to pass the 2 list variables into the popup form, allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects back to the parent, replacing the parents list variables from the list variables received from the child.

        J L 3 Replies Last reply
        0
        • J JollyMansArt

          Partial assumption is correct..... This is the mailmessage as to what it will go to. That part of the application I have working. I am tweaking the (to,cc,bc) before I pass the parameter to the procedure handling the list. To allow for the ability for a popup window with 2 checkbox list boxes. To allow the end user to override or add to the list of email addresses the will be used to send the autogenerated email. It was a requirement being asked in the last second. So I need to pass the 2 list variables into the popup form, allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects back to the parent, replacing the parents list variables from the list variables received from the child.

          J Offline
          J Offline
          JollyMansArt
          wrote on last edited by
          #9

          Here is some of the code behind what I am doing before:

          private void SendEmail(string AlertType, string Subject, string MessageBody)
          {
          string[] MailTo;
          string[] MailCC;
          string MailFrom = "it@peerassistllc.com";
          List<string> EmailToAddress = EmailTo(AlertType);
          List<string> EmailCCAddress = EmailCC(AlertType);

                  if (EmailToAddress.Count > 0)
                  {
                      MailTo = EmailToAddress.ToArray<string>();
                      MailCC = EmailCCAddress.ToArray<string>();
                  }
                  else
                  {
                      MailTo = EmailCCAddress.ToArray<string>();
                      EmailCCAddress.Clear();
                      MailCC = EmailCCAddress.ToArray<string>();
                  }
                  //string Subject = txtAppName.Text + " " + txtVerNumber.Text + " (" + txtCompanyName.Text + ") ";
                  //string MessageBody = Subject + "\\r\\n " + DateTime.Now.ToString();
                  string smtpHOST = txtSMTPServer.Text;
                  int smtpPORT = Convert.ToInt32(txtsmtpPortNumber.Text);
                  string smtpNETAuthUser = txtsmtpServerAuthencationUserName.Text;
                  string smtpNETAuthPassword = txtsmtpServerAuthencationPassword.Text;
                  int i = 0;
          
                  string LogMessage = "Mail From: " + MailFrom;
                  if (MailTo.Length > 0)
                  {
                      LogMessage += "    Mail To: ";
                      for (i = 0; i < MailTo.Length; i++)
                      {
                          LogMessage += MailTo\[i\] + "; ";
                      }
                  }
          
                  //MessageBox.Show(MailCC.Count<string>().ToString());
                  //if (MailCC.Length > 0)
                  if (MailCC.Count<string>() > 0)
                  {
                      LogMessage += "    Mail CC: ";
                      for (i = 0; i < MailCC.Length; i++)
                      {
                          LogMessage += MailCC\[i\] + "; ";
                      }
                  }
                  LogMessage += "     SMTP Host Server: " + txtSMTPServer.Text;
                  LogMessage += "     SMTP Server Port: " + txtsmtpPortNumber.Text;
                  LogMessage += "     SMTP Server UserName Authencation: " + txtsmtpServerAuthencationUserName.Text;
                  LogMessage += "     Message Subject: " + Subject;
                  
                  //send to sql server;
                  StandardProcedures.SQL\_Log(WhatIsMyConnectionString, AlertType, LogMessage, true);
                  StandardP
          
          J 1 Reply Last reply
          0
          • J JollyMansArt

            Partial assumption is correct..... This is the mailmessage as to what it will go to. That part of the application I have working. I am tweaking the (to,cc,bc) before I pass the parameter to the procedure handling the list. To allow for the ability for a popup window with 2 checkbox list boxes. To allow the end user to override or add to the list of email addresses the will be used to send the autogenerated email. It was a requirement being asked in the last second. So I need to pass the 2 list variables into the popup form, allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects back to the parent, replacing the parents list variables from the list variables received from the child.

            J Offline
            J Offline
            JollyMansArt
            wrote on last edited by
            #10

            Here is the Code I am trying to get to work to pass the variable to pass between the parent and child...

            private void ConfirmEmailReceipents(ref List<string> EmailTo, ref List<string> EmailCC)
            {

                    using (frmpopupEmailRecipient popupVerifyEmailRecipients = new frmpopupEmailRecipient(ref EmailTo, ref EmailCC))
                    {
                        // passing this in ShowDialog will set the .Owner 
                        // property of the child form
                        //popupVerifyEmailRecipients
                        popupVerifyEmailRecipients.ShowDialog(this);
                    }
                   using ( frmpopupEmailRecipient f2 = new frmpopupEmailRecipient())
                    {
                        if( f2.Show() == DialogResult.OK )
                        {
                            f2.toEMAIL;
                            f2.ccEMAIL;
            
                            int i = f2.Number1;
                            string s = f2.String1;
                        }
                    }
            
            
                }
            
            J 1 Reply Last reply
            0
            • J JollyMansArt

              Here is some of the code behind what I am doing before:

              private void SendEmail(string AlertType, string Subject, string MessageBody)
              {
              string[] MailTo;
              string[] MailCC;
              string MailFrom = "it@peerassistllc.com";
              List<string> EmailToAddress = EmailTo(AlertType);
              List<string> EmailCCAddress = EmailCC(AlertType);

                      if (EmailToAddress.Count > 0)
                      {
                          MailTo = EmailToAddress.ToArray<string>();
                          MailCC = EmailCCAddress.ToArray<string>();
                      }
                      else
                      {
                          MailTo = EmailCCAddress.ToArray<string>();
                          EmailCCAddress.Clear();
                          MailCC = EmailCCAddress.ToArray<string>();
                      }
                      //string Subject = txtAppName.Text + " " + txtVerNumber.Text + " (" + txtCompanyName.Text + ") ";
                      //string MessageBody = Subject + "\\r\\n " + DateTime.Now.ToString();
                      string smtpHOST = txtSMTPServer.Text;
                      int smtpPORT = Convert.ToInt32(txtsmtpPortNumber.Text);
                      string smtpNETAuthUser = txtsmtpServerAuthencationUserName.Text;
                      string smtpNETAuthPassword = txtsmtpServerAuthencationPassword.Text;
                      int i = 0;
              
                      string LogMessage = "Mail From: " + MailFrom;
                      if (MailTo.Length > 0)
                      {
                          LogMessage += "    Mail To: ";
                          for (i = 0; i < MailTo.Length; i++)
                          {
                              LogMessage += MailTo\[i\] + "; ";
                          }
                      }
              
                      //MessageBox.Show(MailCC.Count<string>().ToString());
                      //if (MailCC.Length > 0)
                      if (MailCC.Count<string>() > 0)
                      {
                          LogMessage += "    Mail CC: ";
                          for (i = 0; i < MailCC.Length; i++)
                          {
                              LogMessage += MailCC\[i\] + "; ";
                          }
                      }
                      LogMessage += "     SMTP Host Server: " + txtSMTPServer.Text;
                      LogMessage += "     SMTP Server Port: " + txtsmtpPortNumber.Text;
                      LogMessage += "     SMTP Server UserName Authencation: " + txtsmtpServerAuthencationUserName.Text;
                      LogMessage += "     Message Subject: " + Subject;
                      
                      //send to sql server;
                      StandardProcedures.SQL\_Log(WhatIsMyConnectionString, AlertType, LogMessage, true);
                      StandardP
              
              J Offline
              J Offline
              JollyMansArt
              wrote on last edited by
              #11

              The ConfirmEmailReceipents is the process I need to work in passing my list to the child then back to the parrent to allow for modifications. Any Suggestions...

              1 Reply Last reply
              0
              • J JollyMansArt

                Partial assumption is correct..... This is the mailmessage as to what it will go to. That part of the application I have working. I am tweaking the (to,cc,bc) before I pass the parameter to the procedure handling the list. To allow for the ability for a popup window with 2 checkbox list boxes. To allow the end user to override or add to the list of email addresses the will be used to send the autogenerated email. It was a requirement being asked in the last second. So I need to pass the 2 list variables into the popup form, allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects back to the parent, replacing the parents list variables from the list variables received from the child.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #12

                JollyMansArt wrote:

                allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects ...

                That is wrong, when you add/delete to a list (which is an object) it still is the same list (i.e. the same object, the difference is it may contain some other items). For the rest, I'm not going to study all that, it is way too much code for anything you may want to do. And AFAIK some of it will not even compile. :)

                Luc Pattyn


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                J 1 Reply Last reply
                0
                • J JollyMansArt

                  Here is the Code I am trying to get to work to pass the variable to pass between the parent and child...

                  private void ConfirmEmailReceipents(ref List<string> EmailTo, ref List<string> EmailCC)
                  {

                          using (frmpopupEmailRecipient popupVerifyEmailRecipients = new frmpopupEmailRecipient(ref EmailTo, ref EmailCC))
                          {
                              // passing this in ShowDialog will set the .Owner 
                              // property of the child form
                              //popupVerifyEmailRecipients
                              popupVerifyEmailRecipients.ShowDialog(this);
                          }
                         using ( frmpopupEmailRecipient f2 = new frmpopupEmailRecipient())
                          {
                              if( f2.Show() == DialogResult.OK )
                              {
                                  f2.toEMAIL;
                                  f2.ccEMAIL;
                  
                                  int i = f2.Number1;
                                  string s = f2.String1;
                              }
                          }
                  
                  
                      }
                  
                  J Offline
                  J Offline
                  JollyMansArt
                  wrote on last edited by
                  #13

                  I think I might of figured out how to pass the list to the child form. By Adding a Public List in the child form. WOrking on testing that But now I have a somewhat new question.... How do I have the child form return the result of Dialogbox.ok? I have set the child form's ok and cancel button's dialog property to the ok and cancel property. But I am unsure how to pass that to the parent form.

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    JollyMansArt wrote:

                    allow the form to add/delete items from the list variable for the (to,cc,bc) email addresses. Then finally pass the new list objects ...

                    That is wrong, when you add/delete to a list (which is an object) it still is the same list (i.e. the same object, the difference is it may contain some other items). For the rest, I'm not going to study all that, it is way too much code for anything you may want to do. And AFAIK some of it will not even compile. :)

                    Luc Pattyn


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                    J Offline
                    J Offline
                    JollyMansArt
                    wrote on last edited by
                    #14

                    I figured out finally how to pass the array to the child and back... Parrent Form:

                    using (frmpopupEmailRecipient popupVerifyEmailRecipients = new frmpopupEmailRecipient())
                    {
                    popupVerifyEmailRecipients.MyEmailTo = EmailTo;
                    popupVerifyEmailRecipients.MyEmailCC = EmailCC;

                                if (popupVerifyEmailRecipients.Show() == DialogResult.OK) //How to do this?
                                {
                                    
                                }
                    
                                EmailTo = popupVerifyEmailRecipients.MyEmailTo;
                                EmailCC = popupVerifyEmailRecipients.MyEmailCC;
                    
                            }
                    

                    Child Form:

                    public partial class frmpopupEmailRecipient : Form
                    {
                    public List<String> MyEmailTo;
                    public List<String> MyEmailCC
                    }

                    Now optionally I would like for learning instead of just closing the frm... How do I modify the child form to return a dialogresult.ok value?

                    L 1 Reply Last reply
                    0
                    • J JollyMansArt

                      I figured out finally how to pass the array to the child and back... Parrent Form:

                      using (frmpopupEmailRecipient popupVerifyEmailRecipients = new frmpopupEmailRecipient())
                      {
                      popupVerifyEmailRecipients.MyEmailTo = EmailTo;
                      popupVerifyEmailRecipients.MyEmailCC = EmailCC;

                                  if (popupVerifyEmailRecipients.Show() == DialogResult.OK) //How to do this?
                                  {
                                      
                                  }
                      
                                  EmailTo = popupVerifyEmailRecipients.MyEmailTo;
                                  EmailCC = popupVerifyEmailRecipients.MyEmailCC;
                      
                              }
                      

                      Child Form:

                      public partial class frmpopupEmailRecipient : Form
                      {
                      public List<String> MyEmailTo;
                      public List<String> MyEmailCC
                      }

                      Now optionally I would like for learning instead of just closing the frm... How do I modify the child form to return a dialogresult.ok value?

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #15

                      A Control (a Form IS a Control) offers the following methods amongst others:

                      public void Show()
                      public DialogResult ShowDialog()

                      and the MSDN page on ShowDialog clearly explains how the return value is determined. :|

                      Luc Pattyn


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                      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