RookieTim
asked on
Viewing Forms from a TreeView Control
I would like to build all of my form navigation into a treeview control that is load from a database (Sql server). I have a user, Jon Doe, as the base node and beneath him are the nodes that he has access to view, i.e., Form1, Form2, Form3, etc. However, I'm not sure how to reference the value of the treeview node, "Form1", to my actual Form1 in solutions explorer.
Please advice
Rookie
Please advice
Rookie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This the code for creating the form
Remember that when adding the form name, you also have to add the form namespace
dim _node as new node
_node.Tag = "MayNameSpace.Form1"
TreeView1.Nodes.Add(_node)
'------------------
Dim f As Object
f = Activator.CreateInstance(T ype.GetTyp e(node.Tag , True))
If you have problems, please let me know it.
Remember that when adding the form name, you also have to add the form namespace
dim _node as new node
_node.Tag = "MayNameSpace.Form1"
TreeView1.Nodes.Add(_node)
'------------------
Dim f As Object
f = Activator.CreateInstance(T
If you have problems, please let me know it.
ASKER
Wguerram-
This is works well. However, my problem is that I want just a single instance of a form open at a given time? Do you have a suggestion on how to maintain just one instance.
I was anticipating using this block of code, but it dosen't seem to be working as well as I'd have hoped.
' MyChildForm is the one I'm looking for which would be f in our instance
Dim childForm As MyChildForm = Nothing
Dim c As Form
For Each c In Me.MdiChildren
If TypeOf c Is MyChildForm Then
' found it
childForm = CType(c, MyChildForm)
Exit For
End If
Next
If Not childForm Is Nothing Then
childForm.Show()
childForm.Focus()
Else
childForm = New MyChildForm()
childForm.MdiParent = Me
childForm.Show()
childForm.Focus()
End If
This is works well. However, my problem is that I want just a single instance of a form open at a given time? Do you have a suggestion on how to maintain just one instance.
I was anticipating using this block of code, but it dosen't seem to be working as well as I'd have hoped.
' MyChildForm is the one I'm looking for which would be f in our instance
Dim childForm As MyChildForm = Nothing
Dim c As Form
For Each c In Me.MdiChildren
If TypeOf c Is MyChildForm Then
' found it
childForm = CType(c, MyChildForm)
Exit For
End If
Next
If Not childForm Is Nothing Then
childForm.Show()
childForm.Focus()
Else
childForm = New MyChildForm()
childForm.MdiParent = Me
childForm.Show()
childForm.Focus()
End If
Check the accepted answer in this thread.
https://www.experts-exchange.com/questions/21098926/How-can-i-contorl-the-menu-in-vb-net.html
https://www.experts-exchange.com/questions/21098926/How-can-i-contorl-the-menu-in-vb-net.html
ASKER
Thank you very much.
You're welcome!
Load the TreeView with the Names of All Forms as Nodes eg. Form1,Form2 etc.
Now on AfterSelect event of TreeView call a Function ShowForm and Pass the name of the form i.e. the TExt of the Node
Now in the function use Select Case on the Names to create reference of the particular form and show it....