Solved

Open Form Based On Table Value

Posted on 2007-11-16
10
458 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:H-SC
Comment Utility
VBRocks,

I keep getting the following error....

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

Expert Comment

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

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

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:H-SC
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
VBRocks,

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

10 Experts available now in Live!

Get 1:1 Help Now