I have a table I am parsing that looks like the following (done as csv)
y,x,a,1
y,x,a,2
y,x,a,3
y,x,b,1
y,x,c,1
y,x,c,2
y,x,d,1
y,x,d,2
y,x,d,3
I would re-structure data into related tables, but I am integrating back
into something that I did not create, and it's just ugly....
I need to load the x and y values into the mynode.Tag field of the root and
child. They are actually the same info for each root level item (ie, for
xya1 and xya2, xy are equal. They are not for display but only for
informational purposes.
I need the tree to be:
a
--1
--2
--3
b
--1
c
--1
--2
d
--1
--2
--3
Here is code I am using:
#region "While Datareader"
while (getdataread.Read())
{
TreeNode m_TreeRoot = new TreeNode();
m_TreeRoot.Text = getdataread.GetSqlString(4).ToString(); // Display Text
m_TreeRoot.Tag = getdataread.GetSqlString(2).ToString(); // Hidden Info
if (strChildTxt != getdataread.GetSqlString(5).ToString())
{
TreeNode m_TreeChild = new TreeNode(); //
m_TreeChild.Text = getdataread.GetSqlString(5).ToString(); // Display Text
m_TreeChild.Tag = Convert.ToString(getdataread.GetSqlInt32(1)); // Hidden
Info
m_TreeRoot.Nodes.Add(m_TreeChild);
treePO.Nodes.Add(m_TreeRoot);
}
else if (strRootTxt != getdataread.GetSqlString(4).ToString() && strChildTxt
== getdataread.GetSqlString(5).ToString())
{
TreeNode m_TreeChild = new TreeNode(); //
m_TreeChild.Text = getdataread.GetSqlString(5).ToString(); // Display Text
m_TreeChild.Tag = Convert.ToString(getdataread.GetSqlInt32(1)); // Hidden
Info
m_TreeRoot.Nodes.Add(m_TreeChild);
treePO.Nodes.Add(m_TreeRoot);
}
strChildTxt = getdataread.GetSqlString(5).ToString();
strRootTxt = getdataread.GetSqlString(4).ToString();
}
#endregion
This gets me:
a
--1
a
--2
a
--3
b
--1
c
--1
c
--2
etc..
As far as speed, its taking about 5 seconds to fill my treeview. It's
parsing about 120 - 150 lines. This is acceptable, although I would not
mind speeding it up a little, most of the time appears to be spent drawing
the treeview, not pasring data.
Darren Shaffer - 06 May 2005 15:23 GMT
One thing you can do to improve performance is use GetValues() instead
of the numerous calles to GetValue() you are making on your data reader.

Signature
Darren Shaffer
.NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
>I have a table I am parsing that looks like the following (done as csv)
> y,x,a,1
[quoted text clipped - 82 lines]
> mind speeding it up a little, most of the time appears to be spent drawing
> the treeview, not pasring data.
Zac Maclean - 06 May 2005 15:48 GMT
I'll try that, but I don't think that will help fix the main issue of the
treeview population.
Zac
> One thing you can do to improve performance is use GetValues() instead
> of the numerous calles to GetValue() you are making on your data reader.
[quoted text clipped - 86 lines]
>> mind speeding it up a little, most of the time appears to be spent
>> drawing the treeview, not pasring data.
Rick Elbers - 08 May 2005 14:05 GMT
Zac,
1) If you dont use beginUpdate the tree gets drawn after EVERY
addition or removal of treenode. Thats whats the problem.
Use beginupdate/endupdate.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemwindowsformstreeviewclassbeginupdatetopic.asp
2) If you have stacks of information to load into your treeview
consider using background thread for loading information in chunks of
10 rootnodes. Not a big deal to make, improves user experience a lot.
Rick
>I'll try that, but I don't think that will help fix the main issue of the
>treeview population.
[quoted text clipped - 90 lines]
>>> mind speeding it up a little, most of the time appears to be spent
>>> drawing the treeview, not pasring data.
Zac Maclean - 10 May 2005 18:41 GMT
Issue was never about the > speed <. Getting about 100 - 150 records out of
40,000 was where my speed problem was. I trimmed the database updated to
each PDA down to around 2000 - 3000 records (Had some filtering problems).
The data read is now fast enough that the draw time is not an issue at all.
My issue was in creating the treeview from the data. I've since fixed that.
I had three other people read my original post, and asked them to tell me
what I was asking about. All three said the primary question was about
creating the treeview. I mentioned the speed at the end, because it was a
secondary issue. "This is acceptable, although I would not mind speeding it
up..."
Thanks for the tip on BeginUpdate / EndUpdate. It looks good that way.
Zac
> Zac,
>
[quoted text clipped - 109 lines]
>>>> mind speeding it up a little, most of the time appears to be spent
>>>> drawing the treeview, not pasring data.