468,301 Members | 1,563 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Treeview / Nodes

LC
Hello all,

Ive been using the treeview and for testing purpose i have created 2 Parent
Nodes and 5 child nodes within each parent node i.e.-

CN = Child Node
Parent Node
- CN
- CN
- CN
- CN
- CN
Parent Node 2
- CN
- CN
- CN
- CN
- CN

1. My question is that i have been advised (not from here) using treeview in
this fashion is not recommended as its bad coding or it will create problems
later - is this true?

2. I cant have a code that would perform some kind of task for each of the
child nodes, even if i could there would be too much confusion and not the
correct way of doing things.
i.e.
Treeview1.Node.ChildNode1(process.Start "Name of my process")

- I know the code definition is incorrect here but thats an example (unless
someone knows the proper code)

So what do you guys reckon?

If you think i need some more reading or understanding on nodes and
treeviews, then please do provide further links.

As always thanks in advance.
Nov 21 '05 #1
3 1667
LC,

I never did it your way, so some guesing in this answer.


1. My question is that i have been advised (not from here) using treeview
in
this fashion is not recommended as its bad coding or it will create
problems
later - is this true?
I would not know why

2. I cant have a code that would perform some kind of task for each of
the
child nodes, even if i could there would be too much confusion and not the
correct way of doing things.
i.e.
Treeview1.Node.ChildNode1(process.Start "Name of my process")

I had to write I never did that, and to be sure it works I made a sample for
you.

\\\needs only a treeview on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("WindowPrograms", _
New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("Notepad")})})
Me.TreeView1.SelectedImageIndex = -1
TreeView1.Nodes(0).Nodes(0).Tag = "notepad.exe"
End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles TreeView1.AfterSelect
If Not e.Node.Tag Is Nothing Then
Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = e.Node.Tag.ToString
p.Start()
End If
End Sub
///

I hope this helps?

Cor
Nov 21 '05 #2
LC
Thanks Cor, that makes a whole lot more sense. Just curious if i made a
program that may hold a lot of nodes/ child nodes (lets say for example sake
Windows Explorer) would you recommend this approach that is using this type
of code throughout the whole program?

Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("WindowPrograms", _
New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("Notepad")})})
Me.TreeView1.SelectedImageIndex = -1
TreeView1.Nodes(0).Nodes(0).Tag = "notepad.exe"

Again thanks very much for your help.

LC

"Cor Ligthert" wrote:
LC,

I never did it your way, so some guesing in this answer.


1. My question is that i have been advised (not from here) using treeview
in
this fashion is not recommended as its bad coding or it will create
problems
later - is this true?


I would not know why

2. I cant have a code that would perform some kind of task for each of
the
child nodes, even if i could there would be too much confusion and not the
correct way of doing things.
i.e.
Treeview1.Node.ChildNode1(process.Start "Name of my process")

I had to write I never did that, and to be sure it works I made a sample for
you.

\\\needs only a treeview on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("WindowPrograms", _
New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("Notepad")})})
Me.TreeView1.SelectedImageIndex = -1
TreeView1.Nodes(0).Nodes(0).Tag = "notepad.exe"
End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles TreeView1.AfterSelect
If Not e.Node.Tag Is Nothing Then
Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = e.Node.Tag.ToString
p.Start()
End If
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #3
LC,

No I would do it like this

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
For i As Integer = 0 To Whatever from my source
TreeView1.Nodes.Add(New TreeNode("Whatever"))
For y As Integer = 0 To Whatever from my source
TreeView1.Nodes(i).Nodes.Add("Whatever"))
TreeView1.Nodes(i).Nodes(y).Tag = "Whatever"
Next
Next
TreeView1.EndUpdate()
End Sub
///

I hope this helps?

Cor

"LC" <LC@discussions.microsoft.com>
Thanks Cor, that makes a whole lot more sense. Just curious if i made a
program that may hold a lot of nodes/ child nodes (lets say for example
sake
Windows Explorer) would you recommend this approach that is using this
type
of code throughout the whole program?

Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("WindowPrograms", _
New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("Notepad")})})
Me.TreeView1.SelectedImageIndex = -1
TreeView1.Nodes(0).Nodes(0).Tag = "notepad.exe"

Again thanks very much for your help.

LC

"Cor Ligthert" wrote:
LC,

I never did it your way, so some guesing in this answer.

>
> 1. My question is that i have been advised (not from here) using
> treeview
> in
> this fashion is not recommended as its bad coding or it will create
> problems
> later - is this true?


I would not know why
>
> 2. I cant have a code that would perform some kind of task for each of
> the
> child nodes, even if i could there would be too much confusion and not
> the
> correct way of doing things.
> i.e.
> Treeview1.Node.ChildNode1(process.Start "Name of my process")
>

I had to write I never did that, and to be sure it works I made a sample
for
you.

\\\needs only a treeview on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("WindowPrograms", _
New System.Windows.Forms.TreeNode() _
{New System.Windows.Forms.TreeNode("Notepad")})})
Me.TreeView1.SelectedImageIndex = -1
TreeView1.Nodes(0).Nodes(0).Tag = "notepad.exe"
End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles TreeView1.AfterSelect
If Not e.Node.Tag Is Nothing Then
Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = e.Node.Tag.ToString
p.Start()
End If
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by serge calderara | last post: by
4 posts views Thread by alanrn | last post: by
3 posts views Thread by Steve Richter | last post: by
5 posts views Thread by Mark Goldin | last post: by
4 posts views Thread by Ian Powell | last post: by
3 posts views Thread by Jan Wrage | last post: by
14 posts views Thread by Mr.D | last post: by
1 post views Thread by | last post: by
1 post views Thread by doemon | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.