I'm working on a vb.net project in Visual Studio. The "Menu" form has a TreeView control. When the end user clicks a node then I want to open the form that corresponds to the selected node. All of the forms are within the same project. I'm basically trying to make the treeview work as a menu or switchboard.
The problem is that there could be 50 to 60 nodes and I'd like to avoid having to do 50-60 case statements or if else statements to open the forms.
So I was working on the code below but I'm getting the following error because I can't cast from a string to a form, so can someone provide any suggestions as to how I can get this to work?
Thank you in advance!
ERROR: Unable to cast object of type 'System.String' to type 'System.Windows.Forms.Form
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim frm As New Form
con.ConnectionString = "Data Source=myServer;Initial Catalog=myDB;Integrated Security=True"
cmd.Connection = con
If e.Node.Text = "PM App" Then
cmd.CommandText = "SELECT FormName FROM Menu WHERE Application = @Form"
frm = cmd.ExecuteScalar()