Hi.
I am getting odd treeview results and hope you can help.
I am parsing a string, "x/y/z", turning it into an array (that
always seems to start with an empty string) and then
using the elements of that array to populate a single tree.
The first non-empty element is the root, the last is a file -
everything in between is a folder.
THE PROBLEM is that I am getting the root with an
empty folder as one tree, then the next element with
all the other nodes below it.
So,
array [1], [2], [3], [4]
Should produce the following results:
-- [1] (root folder)
-------[2] (folder)
------------[3] (folder)
------------[4] (file)
But, I am getting
--[1] (root folder)
------[?] (empty folder with no name)
--[2] (folder)
------[3] (folder)
------[4] (file)
And this pattern repeats down the grid.
Below is the code, I would really appreciate some
clear input help here. Thanks.
public void OnDataBinding(o bject sender, EventArgs e)
{
int count = 0;
TreeView tree = (TreeView)sende r;
GridViewRow container = (GridViewRow)tr ee.NamingContai ner;
if (storedNodes.Co unt != 0)
{
string path = storedNodes.Pop ().ToString();
string[] arr = path.Split('/');
root = new TreeNode();
root.ImageUrl = "folder.gif ";
if (arr[0] != "")
root.Text += arr[0].ToString();
else if (arr[1] != "")
root.Text += arr[1].ToString();
root.SelectActi on = TreeNodeSelectA ction.SelectExp and;
root.PopulateOn Demand = true;
root.SelectActi on = TreeNodeSelectA ction.Expand;
for (int i = 1; i <= arr.Length - 1; i++)
{
if (arr[i] != "")
{
TreeNode node = new TreeNode();
if (i != arr.Length - 1)
{
node.ImageUrl = "folder.gif ";
node.Text += arr[i].ToString();
node.SelectActi on =
TreeNodeSelectA ction.SelectExp and;
node.PopulateOn Demand = true;
node.SelectActi on =
TreeNodeSelectA ction.Expand;
}
else
{
node.ImageUrl = "play.jpg";
node.Text += arr[i].ToString();
node.SelectActi on = TreeNodeSelectA ction.None;
node.Value = "vBrickTree ";
node.SelectActi on =
TreeNodeSelectA ction.Expand;
}
root.ChildNodes .Add(node);
count++;
}
}
tree.Nodes.Add( root);
}
}
I am getting odd treeview results and hope you can help.
I am parsing a string, "x/y/z", turning it into an array (that
always seems to start with an empty string) and then
using the elements of that array to populate a single tree.
The first non-empty element is the root, the last is a file -
everything in between is a folder.
THE PROBLEM is that I am getting the root with an
empty folder as one tree, then the next element with
all the other nodes below it.
So,
array [1], [2], [3], [4]
Should produce the following results:
-- [1] (root folder)
-------[2] (folder)
------------[3] (folder)
------------[4] (file)
But, I am getting
--[1] (root folder)
------[?] (empty folder with no name)
--[2] (folder)
------[3] (folder)
------[4] (file)
And this pattern repeats down the grid.
Below is the code, I would really appreciate some
clear input help here. Thanks.
public void OnDataBinding(o bject sender, EventArgs e)
{
int count = 0;
TreeView tree = (TreeView)sende r;
GridViewRow container = (GridViewRow)tr ee.NamingContai ner;
if (storedNodes.Co unt != 0)
{
string path = storedNodes.Pop ().ToString();
string[] arr = path.Split('/');
root = new TreeNode();
root.ImageUrl = "folder.gif ";
if (arr[0] != "")
root.Text += arr[0].ToString();
else if (arr[1] != "")
root.Text += arr[1].ToString();
root.SelectActi on = TreeNodeSelectA ction.SelectExp and;
root.PopulateOn Demand = true;
root.SelectActi on = TreeNodeSelectA ction.Expand;
for (int i = 1; i <= arr.Length - 1; i++)
{
if (arr[i] != "")
{
TreeNode node = new TreeNode();
if (i != arr.Length - 1)
{
node.ImageUrl = "folder.gif ";
node.Text += arr[i].ToString();
node.SelectActi on =
TreeNodeSelectA ction.SelectExp and;
node.PopulateOn Demand = true;
node.SelectActi on =
TreeNodeSelectA ction.Expand;
}
else
{
node.ImageUrl = "play.jpg";
node.Text += arr[i].ToString();
node.SelectActi on = TreeNodeSelectA ction.None;
node.Value = "vBrickTree ";
node.SelectActi on =
TreeNodeSelectA ction.Expand;
}
root.ChildNodes .Add(node);
count++;
}
}
tree.Nodes.Add( root);
}
}
Comment