Building Treeview questions

M

meh

Greeting All;

I have some questions about how to build a treeview node at runtime.

I get data from a SQL database some time 10 records sometimes 500,000
records. In one of the columns I get a string that looks kind of like
this...

Section 1:section2/section3.section4.section5. etc.

I parse that out based on the delimiters.

I am trying to dynamically build a treeview from this data. the treeview
nodes have a critiriea that I know what level in the tree they are and as I
get to the end of the string I have to assign data to the node.tag
attribute.

So I think that I have a "collection" of Nodes with these attributes.

nod.Name = currTree.SelectedNode.Name.ToString();
nod.Text = currTree.SelectedNode.Text.ToString();
nod.Tag = currTree.SelectedNode.Tag;
nod.ImageIndex = currTree.SelectedNode.ImageIndex;
nod.SelectedImageIndex =
currTree.SelectedNode.SelectedImageIndex;
nod.ToolTipText = currTree.SelectedNode.ToolTipText;

I then go through the process of building the treeview. This takes approx
800 lines of code to do it line-by-line.

So my question is can I make the nodes a collection of objects and then add
the nodes recursively?

I have found some recursive samples but I'm not sure how to assign the above
attributes during the recursion.

Can someone point me in the right direction?

meh
 
M

meh

Thanks For the reply...

I am reading other things from the database at the time but the only
representation I have is the text string. One of the things I'm hoping to
do is give the data that structure so I can write it back with the structure
in it.

thanks for any information
meh

Peter Duniho said:
Greeting All;

I have some questions about how to build a treeview node at runtime.

I get data from a SQL database some time 10 records sometimes 500,000
records. In one of the columns I get a string that looks kind of like
this...

Section 1:section2/section3.section4.section5. etc.

I parse that out based on the delimiters.

I am trying to dynamically build a treeview from this data. the
treeview nodes have a critiriea that I know what level in the tree they
are and as I get to the end of the string I have to assign data to the
node.tag attribute.

[...]
So my question is can I make the nodes a collection of objects and then
add the nodes recursively?

I'm sure you can. But I don't understand why you want an intermediate
collection of objects. Are you going to use that data structure for
something other than initializing the TreeView? If not, then why not just
initialize the TreeView directly from records you get from the database?

Ideally, the database would have records representing parent nodes before
any of the children nodes show up. But based on your example, it looks to
me as though that probably wouldn't matter. If a child node appears
first, you can just create all of the necessary TreeView nodes leading to
it, and then fill them in later as the ancestor nodes are read later in
the database.

Pete
 
M

meh

Morning Peter;

One of the pieces of data that comes out of the database is the name and
unique ID of 1 of the parts. I am assigning that to one of the nodes as its
tag so that the user only has to know its name. When the user clicks on the
name it runs other queries against the database using the unique ID.
This is why I need the structure.
The tree also gets serialized to the hard disk so we don't have to do this
again.

I built a structure for serializing the nodes to file I am trying to use a
like thing to generate the treeview with recursion.

Currently I am doing the tree without recursion but it's approximately 800
lines of code. The recursion process I am trying to use is 14. If I could
get the recursion process to work with the node object it would make the
process a lot more efficient..I think.

Thanks for any input...

meh
 

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