Solved

Finding an instance of an object

Posted on 2008-10-14
4
182 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now