Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:10:05+00:00 2026-06-02T08:10:05+00:00

Currently I am sending one Array List from form2 to form 1 and it

  • 0

Currently I am sending one Array List from form2 to form 1 and it works fine.

Form1 form2 = new Form1(this, SampleArrayList); //pass form reference and an arraylist
form2.Show();
this.Hide();

And on form1 I associate SampleArrayList with local Array List.

Form2 formParent;
ArrayList SampleArrayList;
public MainForm(Form2 par, ArrayList _SampleArrayList)
{            
       InitializeComponent();
       this.formParent = par;
       this.SampleArrayList = _SampleArrayList;
}

However I want to avoid creating new instance of Form1

form2 = new Form1(this, SampleArrayList);

I want to send Array List to currently running instance of Form1. What would be best way to do this. Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:10:08+00:00Added an answer on June 2, 2026 at 8:10 am

    Quote of OP in the comments above:

    Form1 is created first, clicking add button creates Form2. Clicking
    submit button hides Form2 and creates new instance of Form1 along with
    old instance which I didn’t want to dispose of. I want to click submit
    button and go back to running instance of Form1.

    That’s really a larger problem then. Here’s a nice solution that I like.

    public partial class Form1 : Form
    {
        private string dataFromThisForm; //can be whatever
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 otherForm = new Form2();
            //pass some data to other form
            otherForm.SomeData = dataFromThisForm; 
    
            this.Hide();
            otherForm.Show();
    
            //when the other form is closed
            otherForm.FormClosed += (sender2, e2) =>
            {
                this.Show();
    
                string newData = otherForm.NewData;
            };
    
            //when the other form is hidden.
            otherForm.VisibleChanged += (sender2, e2) =>
            {
                this.Show();
    
                string newData = otherForm.NewData;
            };
        }
    }
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            //Use SomeData to populate controls.
        }
    
        public string SomeData { get; set; } //data passed in from other form
    
        public string NewData { get; private set; }  //data to expose to other form
    
        private void button1_Click(object sender, EventArgs e)
        {
            NewData = "SomeDataToPassToForm1";
            //this.Close();
            this.Hide();
        }
    }
    

    A few notes:

    • You’re passing around an ArrayList, rather than strings as I did in
      this example. An ArrayList is a mutable reference type, whereas
      string is immutable. This means that you can just modify the
      ArrayList passed to Form2, and those changes will be reflected in
      the variable in Form1 since they both point to the same underlying
      ArrayList. I left this code in here as it covers the general case
      though.
    • You say that you hide Form2 when you click the submit button.
      Normally in this design you would close it since it won’t be needed
      anymore. If you really don’t plan to use it again I suggest closing
      it. If you really do plan to show that form again then just hiding
      it is fine.
    • If you close Form2 on submit it will fire the FormClosing event, if
      you just hide it it will fire the Visible event. You should probably
      remove one of those two event handlers in my code depending on
      whether you actually close it or hide it. If you sometimes do one and
      sometimes the other then feel free to leave both. You won’t actually
      harm anything (other than confusing people) if you leave both in even
      if you only use one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to the topic of computer networking and sending data to one
I'm trying to make motion controller using the values from android sensors. Currently sending/receiving
I currently sending ipa to friends for testing. Funny thing is, one of my
I am currently sending and receiving SIP messages across a network. When I want
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently we're parsing arp request output from the command line. string cmd = arp
I am currently using two XBees, one of them attached to my computer, and
I am currently making a program in which one of its functions is to
I am writing an application which tests email addresses, for one part of this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.