Solved

Finding an instance of an object

Posted on 2008-10-14
4
187 Views
Last Modified: 2010-04-15
I have used :
Button btn = (Button)this.Controls.Find("button" + strLetter.ToUpper(), true) [0];
to find a control named button.a

How would I find an instance of a class that I have created named myIHCPanelA.
This is not a control so I can't do this:
Specimen sp = (Specimen)this.Controls.Find("myIHCPanel" + strLetter.ToUpper(), true)[0];
0
Comment
Question by:urologic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22712461
When you say 'find an instance of a class', when you create the instance you should have a reference to it, when your instance goes out of scope or you explicitly dispose of it then it will be garbage collected and will no longer exist, so generally speaking if you dont have a reference to it and need to 'find' it then it wont even exist for you to find.
0
 

Author Comment

by:urologic
ID: 22712862
Thanks for the reply.

The instance isn't out of scope, I created it just after loading my form. What I am doing is iterating through a recordset and when I find the line that references specimenA (strLetter) I need to the populate myIHCPanelA.name, myIHCPanelA.description, etc. for several specimens a-x.
0
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 22713281
i see.

Can you not add them to a dictionary...

Dictionary<string,YourType> dict = new Dictionary<string,YourType>();


dict.add("A",instance);
dict.add("B",instance);
dict.add("C",instance);



then ref them via
dict["A"]

etc...
0
 

Author Comment

by:urologic
ID: 22713578
Thanks. I will give that a try.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question