Solved

Viewing Forms from a TreeView Control

Posted on 2004-09-10
7
202 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
ID: 12033409
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
ID: 12035182
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
ID: 12044060
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:RookieTim
ID: 12058735
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
ID: 12058813
0
 

Author Comment

by:RookieTim
ID: 12077584
Thank you very much.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12078075
You're welcome!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SLMGR Switches Are Not Working On KMS Host 3 89
Help with AsEnumerable(), LINQ 4 38
Get number of Files in Directory and Sub Directories 2 39
VB.net and sql server 4 33
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

18 Experts available now in Live!

Get 1:1 Help Now