On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.
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 String con.ConnectionString = "Data Source=myServer;Initial Catalog=myDB;Integrated Security=True" con.Open() cmd.Connection = con If e.Node.Text = "MyApp" Then Exit Sub Else cmd.CommandText = "SELECT FormName FROM Menu WHERE Application = @Form" cmd.Parameters.AddWithValue("@Form", TreeView1.SelectedNode.Text) frm = cmd.ExecuteScalar() con.Close() If frm Is Nothing Then 'The selected node does not have a form Exit Sub Else Dim f As Form = GetFormByName(frm) f.Show() 'Open the form selected in the TreeView control Me.BringToFront() 'Bring the MyAppMenu form to the front to be able to have it appear behind the other forms in the next line Me.SendToBack() 'Send the MyAppMenu form behind the form just opened in the f.show() line End If End If End Sub Private Function GetFormByName(ByVal pFormName As String) As Form 'Try to create a type form using the name specific in pFormName. The False is to prevent an exception because in the If statement we are checking if the Type is null (meaning nothing found) Dim T As Type = Type.GetType(pFormName, False) If T Is Nothing Then 'If nothing is found then add the current namespace (ie. MyApp.Prospects) Dim strFullname As String = Application.ProductName & "." & pFormName T = Type.GetType(strFullname, True, True) 'The second True is to do a case-insensitive search for strFullname End If Return CType(Activator.CreateInstance(T), Form) End Function
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.