Solved

Open Form Based On Table Value

Posted on 2007-11-16
10
460 Views
Last Modified: 2008-02-01
I have a form with a combo on it that cross refrences which form to open based on the selection.  I have this half working.  It does the sql connection and looks up the value but stops and gives an error at the Show refrence in my code

I keep getting an error of
Unable to cast object of type 'system string' to type 'System.Windows.Forms.IWin32Window'.

so I think that it is having trouble taking the value from my table, which is the actual form name to open and translating to mytablevalue.show()
0
Comment
Question by:H-SC
  • 5
  • 4
10 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 20302196
Please post your code.

However, the form name is not the form. You may want to do something like this:

Dim formName as string = ' Get the name here
Dim frm as Form
Select Case formName
  Case "myForm1"
    frm = new myForm1
  Case "myForm2"
    frm = new myForm2
End Select
frm.Show
0
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 20302279
He're another way of doing it:

Let's say your combobox is named "Combobox1":

        'Set this to the name of your project (mine is "Expert")
        Dim sProjectName As String = "Expert"

        Dim frm As Form = _
            Activator.CreateInstance(System.Type.GetType(sProjectName & "." & ComboBox1.Text))

        frm.Show()


0
 
LVL 1

Author Comment

by:H-SC
ID: 20312183
Chaosian,

Here is the code that I currently have:

 Dim conn2 As New SqlClient.SqlConnection("Server= ---------;Database= -------;Trusted_Connection=yes")
        Dim sSQLCMd2 As String = ("select screen from modules where module='{m}'")
        sSQLCMd2 = Replace(sSQLCMd2, "{m}", Combobox1.Text)
        Dim scCmd2 As New SqlClient.SqlCommand(sSQLCMd2, conn2)
        conn2.Open()
        main.Show()
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:H-SC
ID: 20351011
VBRocks,

I keep getting the following error....

{"Value cannot be null.  Parameter name: type"}
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20351499
Put a break point on the Activator.CreateInstance line of code, and check the following:

What does this contain:   sProjectName & "." & ComboBox1.Text

0
 
LVL 1

Author Comment

by:H-SC
ID: 20352094
VBRocks,

It shows the project name as the name of my project  and the form name is the form that I selected in the dropdown that is a form in my project called form2
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352130
So, can you show me exactly?  

Example:  In the Expert project, to open frmMain, It should be like this:  "Expert.frmMain"

Also, do you have your form in a namespace?

0
 
LVL 1

Author Comment

by:H-SC
ID: 20352401
it looks like the above...mine is PROJ5.form2

I dont think that either of the forms are in a unique namespace
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352447
Ok, one possibility is the casing.  Make sure you have the correct case for the names.

For example, "PROJ5" should be exact, not "proj5" or "Proj5"
If form2 is actually "Form2", then correct that and try it again.

So, perhaps it should be like this:
    PROJ5.Form2


0
 
LVL 1

Author Comment

by:H-SC
ID: 20353124
VBRocks,

That was the key....I had form2 in the table as form2 and not Form2.  Many thanks
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Help with AsEnumerable(), LINQ 4 40
How to sort a list of objects using an item in an enclosed list 5 46
get column names from table in vb.net 8 28
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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