After days and hours, could not achieve to do this ...


P

Patrick Penet

Hello MVPs and other Gurus,

I (urgently) need to fill a TreeView in a Windows form with the
data of a text file structured as under :

- begin
Root\
Root\Node1\
Root\Node1\SubNode11\
Root\Node1\SubNode11\SubNode111\
Root\Node1\SubNode11\SubNode112\
Root\Node1\SubNode12\
Root\Node1\SubNode12\SubNode121\
Root\Node1\SubNode12\SubNode122\
Root\Node1\SubNode12\SubNode123\
Root\Node1\SubNode13\
Root\Node1\SubNode14\
Root\Node2\
Root\Node2\SubNode21\
Root\Node2\SubNode21\SubNode211\
Root\Node2\SubNode21\SubNode211\SubNode2111\
Root\Node2\SubNode21\SubNode211\SubNode2111\SubNode2112\
Root\Node2\SubNode21\SubNode211\SubNode2111\SubNode2112\SubNode21121
Root\Node2\SubNode21\SubNode212\
Root\Node2\SubNode21\SubNode213\
Root\Node3\
- end

Any name in this example is fake and can be replaced
with a whatever string matching the structure.

I easily extracted each Node.Text from the file, but after days
and hours roaming around the availabilities of VB.Net (Visual Studio 2003)
and various Internet Sites, I could not achieve to fill the TreeView properly.
;-(

Any tip, link, code, advice, and support will be highly appreciated.

TIA to all.
Patrick Penet
:)

PS: sorry for crossposting in the VB.Net and Visual Studio related NGs
but it's a matter of time now.
 
Ad

Advertisements

R

Richard Owlett

Patrick said:
Hello MVPs and other Gurus,

I (urgently) need to fill a TreeView in a Windows form with the
data of a text file structured as under :

- begin
Root\
Root\Node1\
Root\Node1\SubNode11\
Root\Node1\SubNode11\SubNode111\
Root\Node1\SubNode11\SubNode112\ [snip]

PS: sorry for crossposting in the VB.Net and Visual Studio related NGs
but it's a matter of time now.

I think you need a better problem description.
It probably makes excellent sense to to someone working with the same
set of tools you use. We have a saying of "not being able to see
forest for the trees". I, as an "and other", can not see past the
"leaves". ( bad pun, very bad pun ;)
 
C

Cor

Hi Patrick,

I am not a MVP and I am feeling me no guru.
But maybe you can use this?

It is not exactly as you told it.

\\\
For i As Integer = 1 To 9
Dim tn As New TreeNode("Root\Node" & i.ToString & "\")
TreeView1.Nodes.Add(tn)
Dim sn As New TreeNode
For j As Integer = 1 To 5
sn = tn.Nodes.Add("Root\Node" & i.ToString & "\SubNode\" & _
i.ToString & j.ToString)
Dim sn2 As New TreeNode
For h As Integer = 1 To 5
sn2 = sn.Nodes.Add("Root\Node" & i.ToString & "\SubNode\" & _
i.ToString & j.ToString & "\" _
& "SubNode" & i.ToString & j.ToString & h.ToString)
Next
Next
Next
///
I hope this helps?

Cor
 
R

Robert

Hi,

In addition to this piece off code, read your text-file line by line and use
the " Split" function.

It's just an idea.....

Robert
 
P

Patrick Penet

Hi Cor,

Thank your for answering, but the code that you
proposed will produce a "regular" TreeView, I mean
that each TreeNodes would have the same number of
subNodes etc., which is not my aim (the values of i, j and h
are not predictible line by line, as shown in example).

As I explained, I could extract each node name with the Split
function, but I cannot figure out how to produce the code that
would add the node at the right place one by one.

It might be, I guess, some recursive sub that would loop
to itself until the branch is completed, but again how ?

Root\
Root\Node1\
Root\Node1\SubNode11\
Root\Node1\SubNode11\SubNode111\
- up to here, it's easy because regular -

Root\Node1\SubNode11\SubNode112\
Root\Node1\SubNode12\
- there, I'm getting problems, I am unable to add SubNode112
to SubNode11 nodes collection, idem for any next nodes regarding
the length of the branch -

I tried building collections, and then add them to the TreeView :
Coll1(Node1, Node2, Node3)
Coll2(SubNode11, SubNode12, SubNode13, SubNode14, SubNode21)
etc.
It's not working either, because Node3 do not have any subnode and
Node2 have 5 levels of subnodes, for example.
This is the point.
;-(((

Sorry for being so boring, but I am really facing this since days.

Thank you.
Patrick
 
P

Patrick Penet

Hi Richard,
Sorry for being unclear, please see my answer to Cor
it might be clearer.
Patrick

Richard Owlett said:
Patrick said:
Hello MVPs and other Gurus,

I (urgently) need to fill a TreeView in a Windows form with the
data of a text file structured as under :

- begin
Root\
Root\Node1\
Root\Node1\SubNode11\
Root\Node1\SubNode11\SubNode111\
Root\Node1\SubNode11\SubNode112\ [snip]

PS: sorry for crossposting in the VB.Net and Visual Studio related NGs
but it's a matter of time now.

I think you need a better problem description.
It probably makes excellent sense to to someone working with the same
set of tools you use. We have a saying of "not being able to see
forest for the trees". I, as an "and other", can not see past the
"leaves". ( bad pun, very bad pun ;)
 
Ad

Advertisements

P

Patrick Penet

Hello Robert,

I did use the split function to extract the node names. The
problem is how to deal with them. Please see my answer to
Cor.

Best regards.
Patrick
 
C

Cor

Hi Patrick,
Thank your for answering, but the code that you
proposed will produce a "regular" TreeView, I mean
that each TreeNodes would have the same number of
subNodes etc., which is not my aim (the values of i, j and h
are not predictible line by line, as shown in example).
No it is not.

Just a little bit of own adding will do something, but here I did it
completly for you, although that I did not count exactly all the nodes.

You have to add of course your own texts, this is an example.

I hope this helps?

Cor

Dim l As Integer() = {0, 0, 1, 0, 1, 5}
Dim t As New TreeNode("Root")
TreeView1.Nodes.Add(t)
For i As Integer = 1 To 5
Dim tn As New TreeNode
tn = t.Nodes.Add("Root\Node" & i.ToString & "\")
Dim sn As New TreeNode
For j As Integer = 1 To l(i)
sn = tn.Nodes.Add("Root\Node" & i.ToString & "\SubNode\"
& _
i.ToString & j.ToString)
Dim sn2 As New TreeNode
For h As Integer = 1 To l(6 - j)
sn2 = sn.Nodes.Add("Root\Node" & i.ToString &
"\SubNode\" & _
i.ToString & j.ToString & "\" _
& "SubNode" & i.ToString & j.ToString & h.ToString)
Next
Next
Next
 
Ad

Advertisements

P

Patrick Penet

Many thanks, Cor, this will help me a lot ...
once I clearly understand the logic behind
and how I can adapt it to my needs.
:)))

Thanks again and cheers.
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top