By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,973 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,973 IT Pros & Developers. It's quick & easy.

Treeview / Nodes

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.