Treeview Data fill

  • Thread starter Thread starter Zac Maclean
  • Start date Start date
Z

Zac Maclean

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.
 
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.
--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 
I'll try that, but I don't think that will help fix the main issue of the
treeview population.

Zac
 
Back
Top