Click here to Skip to main content
16,011,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application using treeview. the names of the node are similar to the name of used application forms. i want when i click the node i will be able to return node name as the name of the form so that i use one line of code to show the application form..

like node.name.show
Posted
Updated 18-Jun-10 11:33am
v2

I ussed this function and it worked.i named the not similar to forms

VB
Private Function GetFormByName2(ByVal formName As String) As Object
        Dim myasm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

        Try
            Return myasm.CreateInstance(myasm.GetName.Name.Replace(" ", "_") & "." & formName)

        Catch ex As Exception
            Return Nothing
        End Try

    End Function

//on tree view event after select

GetFormByName2(e.Node.Name.ToString).show()
 
Share this answer
 
v4
Why does it have to be one line ? It will be a long line. I believe you can use reflection to do this, but of course, you will write a lot of code if you want to also interact with this form in any way.

Of course, given that the forms in your app are known at design time, it would make more sense to write code that just checks the known values and branches to show the known forms.
 
Share this answer
 
v2
Christian is of course correct. His suggestion would probably be the best way.

However if you do not have enormous numbers of Forms and you don't mind having them all in memory at the same time, you could use the TreeViewNode.Tag property to store the appropriate form for each node.

This[^] on MSDN, the example shows how you can do this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900