• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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

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
joshcrosby
Asked:
joshcrosby
  • 3
  • 2
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
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
 
joshcrosbyAuthor Commented:
I'm sorry can you elaborate a bit, not sure what you mean
0
 
Expert1701Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
joshcrosbyAuthor Commented:
Thanks a ton, that makes sense, damn that saved a ton of time, thanks again.
0
 
joshcrosbyAuthor Commented:
man you have no idea how much code and speed that changed, thanks a million.
0
 
Expert1701Commented:
Thanks for posting that feedback; it's very rewarding to know that helped!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now