Solved

Viewing Forms from a TreeView Control

Posted on 2004-09-10
7
200 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:RookieTim
  • 4
  • 2
7 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
Comment Utility
Well what I understand is that you would show a list of all forms a particular user has access to on a TreeView and when the user clicks on them you would open that form. If this is what you want and you are using VB.NET

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....
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
Comment Utility
Hope this helps.

You can add your form names to the tag property of the node and in the after select event you can create an instance of the form like this:

dim f as Object
f = System.Activator.CreateInstance(Type.GetType(node.Tag))

if not isnothing(f) then
   f .Show
end if

I think you have to add the namespace and form name, i don't access to vb now.

node.Tag = "MyNameSpace.Form1"

Check in the project properties to see the name space.

Hope this helps.
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
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(Type.GetType(node.Tag, True))

If you have problems, please let me know it.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:RookieTim
Comment Utility
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
 
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
0
 

Author Comment

by:RookieTim
Comment Utility
Thank you very much.
0
 
LVL 8

Expert Comment

by:wguerram
Comment Utility
You're welcome!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

14 Experts available now in Live!

Get 1:1 Help Now