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

Fill a treeview

P: n/a
Hello,

I have to fill a treeview with data in a text file

text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this

|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?

It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview

Thanks

Nov 9 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
You need to try a little...

Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?

"sf********@gmail.com" wrote:
Hello,

I have to fill a treeview with data in a text file

text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this

|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?

It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview

Thanks

Nov 9 '07 #2

P: n/a
On 9 nov, 16:46, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
You need to try a little...

Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?

"sfauchi...@gmail.com" wrote:
Hello,
I have to fill a treeview with data in a text file
text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this
|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?
It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview
Thanks- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
My problem is not to add node if it already exists, and I have some
problem to find the algorithm!!!

Nov 9 '07 #3

P: n/a
If you have split the string into words [], you would have a loop like such:

dim wordindex as integer = 0
dim treenodes as TreeNodeCollection = TreeView1.Nodes()

while (wordindex < words.length)
dim found as boolean = false

' find the word in the current level of nodes
for each (TreeNode tn in treenodes)
if tn.text = words [wordindex] then
treenodes = tn.Nodes()
found = true
break
endif
next

' did not find the node so add a new one
if (not found) then
treenodes.add(new TreeNode(words[wordindex]))
treenodes = treenodes.nodes ' this will be empty
endif
wordindex = wordindex + 1
end while
"sf********@gmail.com" wrote:
On 9 nov, 16:46, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
You need to try a little...

Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?

"sfauchi...@gmail.com" wrote:
Hello,
I have to fill a treeview with data in a text file
text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this
|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?
It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview
Thanks- Masquer le texte des messages pricidents -
- Afficher le texte des messages pricidents -

My problem is not to add node if it already exists, and I have some
problem to find the algorithm!!!

Nov 9 '07 #4

P: n/a
Note, I didn't type this in to Visual Studio, so there are likely typing
errors, but you should get the idea.

"Family Tree Mike" wrote:
If you have split the string into words [], you would have a loop like such:

dim wordindex as integer = 0
dim treenodes as TreeNodeCollection = TreeView1.Nodes()

while (wordindex < words.length)
dim found as boolean = false

' find the word in the current level of nodes
for each (TreeNode tn in treenodes)
if tn.text = words [wordindex] then
treenodes = tn.Nodes()
found = true
break
endif
next

' did not find the node so add a new one
if (not found) then
treenodes.add(new TreeNode(words[wordindex]))
treenodes = treenodes.nodes ' this will be empty
endif
wordindex = wordindex + 1
end while
"sf********@gmail.com" wrote:
On 9 nov, 16:46, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
You need to try a little...
>
Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?
>
>
>
"sfauchi...@gmail.com" wrote:
Hello,
>
I have to fill a treeview with data in a text file
>
text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
>
and i want it like this
>
|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
>
Someone have an idea?
>
It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview
>
Thanks- Masquer le texte des messages pricidents -
>
- Afficher le texte des messages pricidents -
My problem is not to add node if it already exists, and I have some
problem to find the algorithm!!!
Nov 9 '07 #5

P: n/a
On 9 nov, 19:05, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
Note, I didn't type this in to Visual Studio, so there are likely typing
errors, but you should get the idea.

"Family Tree Mike" wrote:
If you have split the string into words [], you would have a loop like such:
dim wordindex as integer = 0
dim treenodes as TreeNodeCollection = TreeView1.Nodes()
while (wordindex < words.length)
dim found as boolean = false
' find the word in the current level of nodes
for each (TreeNode tn in treenodes)
if tn.text = words [wordindex] then
treenodes = tn.Nodes()
found = true
break
endif
next
' did not find the node so add a new one
if (not found) then
treenodes.add(new TreeNode(words[wordindex]))
treenodes = treenodes.nodes ' this will be empty
endif
wordindex = wordindex + 1
end while
"sfauchi...@gmail.com" wrote:
On 9 nov, 16:46, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
You need to try a little...
Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?
"sfauchi...@gmail.com" wrote:
Hello,
I have to fill a treeview with data in a text file
text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this
|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?
It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview
Thanks- Masquer le texte des messages pricidents -
- Afficher le texte des messages pricidents -
My problem is not to add node if it already exists, and I have some
problem to find the algorithm!!!- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Thank you for your help, I did nearly the same but i used
"treenode.find" function, but it's very slow, i have nearly 20000
lines in my text file.
I try to optimizise it..... Not easy

Nov 10 '07 #6

P: n/a
If you sort the strings on each item, so that your example is:

A.B.A.Var1
A.B.C.D.Var1
A.B.C.D.var2
B.A.C.var2
B.C.D.var3

Then you should be able to optimize by just looking at the last node under
the current node. I didn't make the assumption because your example did not
sort, but, if that is acceptable, then I would go for it.

"sf********@gmail.com" wrote:
On 9 nov, 19:05, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
Note, I didn't type this in to Visual Studio, so there are likely typing
errors, but you should get the idea.

"Family Tree Mike" wrote:
If you have split the string into words [], you would have a loop like such:
dim wordindex as integer = 0
dim treenodes as TreeNodeCollection = TreeView1.Nodes()
while (wordindex < words.length)
dim found as boolean = false
' find the word in the current level of nodes
for each (TreeNode tn in treenodes)
if tn.text = words [wordindex] then
treenodes = tn.Nodes()
found = true
break
endif
next
' did not find the node so add a new one
if (not found) then
treenodes.add(new TreeNode(words[wordindex]))
treenodes = treenodes.nodes ' this will be empty
endif
wordindex = wordindex + 1
end while
"sfauchi...@gmail.com" wrote:
On 9 nov, 16:46, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
You need to try a little...
Which part are you having trouble with? Splitting the string, creating the
nodes, coming up with an algorithm?
"sfauchi...@gmail.com" wrote:
Hello,
I have to fill a treeview with data in a text file
text file
A.B.C.D.Var1
A.B.C.D.var2
A.B.A.Var1
B.A.C.var2
B.C.D.var3
and i want it like this
|A------B-----C-----D------Var1
| | |--Var2
| |--A---- Var1
|B------A------C----Var2
|--C------D----Var1
Someone have an idea?
It's like having a list of file with the fullpath in a text file and
that you want to create a hierarchy in a treeview
Thanks- Masquer le texte des messages pricidents -
- Afficher le texte des messages pricidents -
My problem is not to add node if it already exists, and I have some
problem to find the algorithm!!!- Masquer le texte des messages pricidents -
- Afficher le texte des messages pricidents -

Thank you for your help, I did nearly the same but i used
"treenode.find" function, but it's very slow, i have nearly 20000
lines in my text file.
I try to optimizise it..... Not easy

Nov 10 '07 #7

P: n/a
sf********@gmail.com wrote:
it's very slow, i have nearly 20000 lines in my text file.
And is your user expected to view each and every one of these 20,000!?

I should think not!

When you load the form, scan through the file and add /only/ the root
nodes into the Tree:

- A
- B

etc ...

Then, when the user attempts to /expand/ one of those Nodes, rescan the
file (or whatever storage structure you loaded the file into) and add
/just/ the nodes immediately below the node they clicked on, e.g.:

- A
- B
- A
- C

Because every TreeNode has its own Nodes Collection, it's very easy to
make this routine generic enough that it will work anywhere in the Tree
and the user only loads (and, therefore, waits for) the entries that
they're actually interested in.

HTH,
Phill W.
Nov 12 '07 #8

P: n/a
On 12 nov, 15:11, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-k>
wrote:
sfauchi...@gmail.com wrote:
it's very slow, i have nearly 20000 lines in my text file.

And is your user expected to view each and every one of these 20,000!?

I should think not!

When you load the form, scan through the file and add /only/ the root
nodes into the Tree:

- A
- B

etc ...

Then, when the user attempts to /expand/ one of those Nodes, rescan the
file (or whatever storage structure you loaded the file into) and add
/just/ the nodes immediately below the node they clicked on, e.g.:

- A
- B
- A
- C

Because every TreeNode has its own Nodes Collection, it's very easy to
make this routine generic enough that it will work anywhere in the Tree
and the user only loads (and, therefore, waits for) the entries that
they're actually interested in.

HTH,
Phill W.
Yes it's true

What I have to do, is to fill a tree view and also, create an XML File
looking like this

<Root>A</Root>
<Child>B</Child>

<Root>A.B</Root>
<Child>C</Child>
<Child>A</Child>

<Root>A.B.C</Root>
<Var>Var1</Var>
<Var>Var2</Var>

<Root>A.B.A</Root>
<Var>Var1</Var>

<Root>B</Root>
<Child>A</Child>
<Child>C</Child>

<Root>B.A</Root>
<Child>C</Child>

<Root>B.C</Root>
<Child>D</Child>

<Root>B.A.C</Root>
<Var>Var2</Var>

<Root>B.C.D</Root>
<Var>Var3</Var>

Nov 12 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.