473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Fill a treeview

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
8 1979
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JohnnyB via DotNetMonster.com | last post by:
Hello, I dont know, if this has already been asked before, I'm sorry if so. VisualBasic: My problem (happens with TreeView, not with AxWebBrowser): treeview uses (no matter, if dock = left,...
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
2
by: Ole Baba | last post by:
In Form1.cs I have defined the "InstituteAdministrator" class which contains ListView "listViewAddress". In a second file (FormTreeView.cs) I have the class FormTreeView with the method...
2
by: PawelR | last post by:
Hello Group, I have DataTable dt with 3 Columns (id, GroupName, ItemName). How group in TreeView items by GroupName? EX: myTable: id GroupName ItemName 1 Group1 ...
2
by: Adrien Reboisson | last post by:
I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I installed SQL Server 2005 Express, created a blank project, dropped a TreeView, a ListView and a DataGridView : DB objects...
1
by: Luqman | last post by:
I am using Oracle Database Scott.Emp table with Parent/Child relation keys. How can I fill the ASP.Net 2.0 TreeView Control using Sql Data Source. As the TreeView just uses xmldatasource, is it...
2
by: RP | last post by:
I have an Access Table with following columns: GID (auto number) PID number TreeID Text ItemName Text This table consists of records in the following manner: GID PID TreeID ...
0
by: mdevenney | last post by:
My company doesn't allow for the use of .pst files. So to archive email we have to select the email(s) and click save as or drag them to a folder. I want to write a c# app that will show your...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.