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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:20:28+00:00 2026-05-10T23:20:28+00:00

I’m using .Net 2.0 and this is driving me crazy but there’s probably some

  • 0

I’m using .Net 2.0 and this is driving me crazy but there’s probably some easy thing I’m not doing that I am now too confused to see.

I have an application that has a bespoke collection of objects in it, only the main form should be able to change the contents of that collection and all other forms should be able to read from it.

Actually there’s only one other form but I need it to have the capability of being called multiple times as it edits different items in the bespoke collection. To make the child form a dialog is therefore impractical. The ability to open multiple instances of this form containing different items from the collection is necessary.

I just can’t seem to think of a way of making all forms revolve around the same instance of the collection. Like I say I’m probably missing something obvious but I have ceased to be able to think about the problem properly.

EDIT: Yikes! I can’t have explained myself very well. All subforms should be able to read and write collection items, but I want to only use one instance of the collection at a time whilst the programme is running.

EDIT 2: It turned out that what I needed was a singleton. I have implemented a similar solution in a different project now. Thanks to the commenter below who didn’t actually leave an answer I can mark as the correct one, even though they nailed it.

  • 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. 2026-05-10T23:20:28+00:00Added an answer on May 10, 2026 at 11:20 pm

    If the main form needs read/write access but other forms don’t, then I would make the collection a property of your main form that is read/write from within your form, but read only from outside your form. You can do this using something like:

    C#

    private myCollection _MyCollection;  public myCollection MyCollection {      get { return _MyCollection.AsReadOnly(); }      private set { _MyCollection = value; }  }  

    VB

    Private _MyCollection As myCollection Public Property MyCollection() As myCollection   Get      Return _MyCollection.AsReadOnly   End Get   Private Set(ByVal value As myCollection)     _MyCollection = value   End Set End Property 

    Then you can reference your collection from inside your form by referencing either MyCollection or _MyCollection as you choose, but from outside your form, the collection will be ReadOnly and therefore not editable.

    Edit: After your edit, it does look like what you’re after is a singleton as previously suggested does this mean that all instances of your forms should be able to edit this collection or not? If so, then put your collection into a static class:

    Private _MyCollection as myCollection = Nothing Public Shared ReadOnly Property MyCollection() As myCollection    Get       If _MyCollection is Nothing Then _MyCollection = New myCollection       Return _MyCollection    End Get End Property 

    Now the first time the collection is referenced from within one of your forms it will instantiate a new collection which you can then add/remove items from. Every time you reference the collection from this or one of your other forms, it will already have been instantiated, so it will return the collection that was originally instantiated. None of the forms however will have the ability to set a new collection, just reference the one instantiated by the singleton pattern.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.