Newbie with Treeview Problem

  • Thread starter Thread starter Oh-its-all-gone-wrong
  • Start date Start date
O

Oh-its-all-gone-wrong

Hi All,
I have a TreeView setup with 2 Items on it. Node1, Node2. I would Like to be
able to open a form called Form1, when I double click on Node1, Form 2 when
I double click on Node 2. I`ve done a google search but can`t find to much
info on it.

Could somebody possible point me in the right direction with a bit of code
or link please?

Many Thanks

Si
 
This is easy if you're using VS 2005 (.NET 2.0)
Add an event handler for the the TreeView.NodeMouseDoubleClick event and
create/show your forms in there

/claes
 
In VS 2003, you could trap the DoubleClick event :

Private Sub TreeView1_DoubleClick(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TreeView1.DoubleClick
Dim selNode as TreeNode = TreeView1.SelectedNode
If Not selNode is Nothing Then
If selNode.Text = "Node 1" Then
'Open Form 1
Dim frm as new Form1()
frm.Show()
Else
'Open Form 2
Dim frm as new Form2()
frm.Show()
End if
End if
End Sub

HTH,

Regards,

Cerebrus.
 
Also, if you want to dynamically load forms, you can do this using
reflection. It's not as hard as it sounds, and I can provide asimple code
sample if you're interested.

This is as opposed to having a case statement for every node (which works
absolutely just fine). I'm talking for example if you want one function that
will open the appropriate form no matter how many nodes you add, without
adding more case statements.

Good luck.
 
Back
Top