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 9140261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:35+00:00 2026-06-17T09:29:35+00:00

I have a query regarding maintaining a List in between two windows forms. It’s

  • 0

I have a query regarding maintaining a List in between two windows forms. It’s for a project where I need to create an address book.

I have chosen to maintain the contact details in the form of a List. My first windows form (form1) contains a master copy of a list AddressBook, which contains the address book.
I hardcoded 4 entries into the address book list in order to experiment and get the simple functions such as ‘add’ and ‘edit’ working.

I have a second windows form called Add, in which I can add new entries to the list. This works fine. I can add a new contact in the ADD form and this shows up in the initial form1, master form.

My problem arises in the EDIT form. I pass the AddressBook (master) list to the EDIT form. The EDIT form takes the master list and I am able to manipulate the records in that list. However when it comes to sending back the new list to the master page (form1), it does not pick it up. I am using the same code as I do in the ADD form which successfully sends back the new list. However this code does not work when sending back an edited list.

Here is my AddressBook property within form1

public List<Contact> addressBook;
    public List<Contact> AddressBook
    {

       get { return addressBook;} 
       set {addressBook = value;} 

    }

Within EDIT:

public Edit()

    {
        InitializeComponent();           
        temp = Master.AddressBook;    // temp is the temporary List I update within EDIT         

    }

** I then have my algorithm which successfully lets me EDIT the list temp. the list temp now has the edited list**

then when I hit the save button, I use the following code;

Master.AddressBook = temp;

All I need is for the list temp to be sent back to form1.

the code Master.AddressBook = temp; WORKS for when I add values to the list through the ADD form.

ADD FORM:

 public Add()
    {

        InitializeComponent();
        temp = Master.AddressBook;


    }


       **** code to add a new record into the list temp. the new record is called newRecord**********



    private void btnAddClose_Click(object sender, EventArgs e)
    {
        stor.AddressBook = temp; // when I hit close on the form, it updates the master     list AddressBook 
        this.Close(); 
    }

This is all probably very poorly worded but in essence the only bit where my code fails is when I want to change my master Addressbook within form1 by replacing it with the list temp, which is the edited list from my EDIT form.

I think it’s something to do with my AddressBook property. But this doesn’t explain why I can replace AddressBook with a list containing new records but I can’t replace it with a list containing edited records.

  • 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-17T09:29:36+00:00Added an answer on June 17, 2026 at 9:29 am

    One way to accomplish this would be to make the list in Master static.

    Master:

        public static List<Contact> AddressBook { get; set; }
    

    Note: You do not need the backing variable, and if you do want to use it, best practices would suggest that it be private. If you do decide to use it, it will also need to be static.

    In the Add form, you would then gather the data to create a new Contact object and temp should, in fact, be just a Contact object.
    Add Form:

    private Contact newRecord = null;
    public Add()
    {
        InitializeComponent();
        newRecord = new Contact();
    }
    
    /**** code to add the user-input to the new Contact object ****/
    
    private void btnAddClose_Click(object sender, EventArgs e)
    {
        Master.AddressBook.Add(newRecord);
        this.Close(); 
    }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query regarding to find out which is day (in given list)
I have a query regarding the directory returned from Path.GetTempPath() function. It returns C:\Documents
I have a query regarding PLSQL exceptions and how to handle them in Java
I have a query here regarding the value given to the update attribute of
I have a few queries regarding columns in Postgres CSV Log. Query 1 Following
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have query regarding selected key in JavaScript. I am developing a sql query
I have query regarding the disposing of an object. The scenario is as follows.
I have a query regarding accessibility of top level class from member inner class.
I have one query regarding the (UITextfield and Webservice) for example When i start

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.