[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

** No Title can explain this one ** check it out :)

Posted on 2006-03-26
6
Medium Priority
?
265 Views
Last Modified: 2010-04-16
Okay, probably a major bad on my part but I thought it would be clever to create a look up table in sql server that holds the name of the form i.e lookForm1, description Example Form, display name Example

i.e. values from the table
"lookform1", "Form Test", "This is Test form 1"
"lookform2", "Form Test 2", "This is another Test"
etc....

this was fine for a couple of forms, bound to a dropdown list to pull the id(lookform1) and displayname(Form Test) so that when a user clicks this the form displays as follows

i.e.
string _form = "look" + ddlLookupTables.SelectedValue.ToString();
                  
                        switch(_form)
                        {
                              case "lookCallStatus":
                                    lookCallStatus frm = new ERP.Forms.LookupForms.lookCallStatus();
                                    frm.Show();
                                    break;
                              case "lookCallType":
                                    lookCallType frm1 = new ERP.Forms.LookupForms.lookCallType();
                                    frm1.Show();
                                    break;

Now the problem, the issue is that these lookup forms have grown dramatically and I'm tired of typing this shit over and over.

is there a way to pull that id (lookform1) and actually cast it as a form so that I can just do something like this.
string _form = "look" + ddlLookupTables.SelectedValue.ToString();
string_form.ShowDialog();

bugging the hell out of me and it's my fault hoping someone has a good idea.

0
Comment
Question by:joshcrosby
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 16293144
Hi,

  You can do that using Activator.CreateInstance, here's a sample


                  string s = "Form2";                  

                  Form frm = (Form)Activator.CreateInstance("urAssemblyName","urAssemblyName.Form2").Unwrap();
                  
                  frm.Show();            

Regards,
Mohammed
0
 
LVL 1

Author Comment

by:joshcrosby
ID: 16294922
I'm sorry can you elaborate a bit, not sure what you mean
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 2000 total points
ID: 16295774
Here is an example,

  string _form = ddlLookupTables.SelectedValue.ToString();

  Form frm = (Form)Activator.CreateInstance(Type.GetType(_form));
  frm.Show();

to determine how to refer to the forms in the database, use this code:

  System.Diagnostics.Debug.WriteLine(typeof(lookCallStatus).FullName);

e.g:

  If typeof(lookCallStatus).FullName returns "WindowsApplication1.lookCallStatus" then you would call Activator.CreateInstance(Type.GetType("WindowsApplication1.lookCallStatus")) to create an instance of the lookCallStatus form.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:joshcrosby
ID: 16297202
Thanks a ton, that makes sense, damn that saved a ton of time, thanks again.
0
 
LVL 1

Author Comment

by:joshcrosby
ID: 16297253
man you have no idea how much code and speed that changed, thanks a million.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 16297305
Thanks for posting that feedback; it's very rewarding to know that helped!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 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