凌乱的TreeView结果 [英] Messy TreeView Results
问题描述
嗨。
我得到奇怪的树视图结果并希望你能提供帮助。
我正在解析一个字符串,x / y / z",把它变成一个数组(
似乎总是以一个空字符串开头)然后
使用该数组的元素来填充一个树。
第一个非空元素是根,最后一个是文件 -
介于两者之间的是文件夹。
问题在于我将一个
空文件夹作为一个树获得根,然后下一个元素与
下面的所有其他节点。
所以,
数组[1],[2],[3],[4]
应该产生以下结果:
- [1](根文件夹)
------- [2](文件夹)
------------ [3](文件夹)
------------ [4](文件)
但是,我得到了
- [1](根文件夹)
- ---- [?](没有名字的空文件夹)
- [2](文件夹)
------ [3](文件夹)
------ [4](文件)
这个模式重复下来。
下面是代码,我真的很感激一些
清除输入帮助在这里。谢谢。
public void OnDataBinding(对象发送者,EventArgs e)
{
int count = 0;
TreeView树=(TreeView)发件人;
GridViewRow容器=(GridViewRow)tree.NamingContainer;
if(storedNodes.Count!= 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.SelectAction = TreeNodeSelectAction.SelectExpand;
root.PopulateOnDemand = true;
root.SelectAction = TreeNodeSelectAction.Expand;
for(int i = 1; i< = arr.Length - 1; i ++)
{
if( arr [i]!="")
{
TreeNode节点=新TreeNode();
if(i!= arr.Length - 1)
{
node.ImageUrl =" folder.gif";
node.Text + = arr [i] .ToString();
node.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.PopulateOnDemand = true;
node.SelectAction =
TreeNodeSelectAction.Expand;
}
else
{
node.ImageUrl =" play.jpg";
node.Text + = arr [i] .ToString();
node.SelectAction = TreeNodeSelectAction.None;
node.Value =" vBrickTree";
node.SelectAction =
TreeNodeSelectAction.Expand;
}
root.ChildNodes.Add(节点);
count ++;
}
}
tree.Nodes.Add(root);
}
}
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(object sender, EventArgs e)
{
int count = 0;
TreeView tree = (TreeView)sender;
GridViewRow container = (GridViewRow)tree.NamingContainer;
if (storedNodes.Count != 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.SelectAction = TreeNodeSelectAction.SelectExpand;
root.PopulateOnDemand = true;
root.SelectAction = TreeNodeSelectAction.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.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.PopulateOnDemand = true;
node.SelectAction =
TreeNodeSelectAction.Expand;
}
else
{
node.ImageUrl = "play.jpg";
node.Text += arr[i].ToString();
node.SelectAction = TreeNodeSelectAction.None;
node.Value = "vBrickTree";
node.SelectAction =
TreeNodeSelectAction.Expand;
}
root.ChildNodes.Add(node);
count++;
}
}
tree.Nodes.Add(root);
}
}
推荐答案
" pbd22" < du ***** @ gmail.com写信息
新闻:c3 ************************* ********* @ f13g2000 hsa.googlegroups.com ...
"pbd22" <du*****@gmail.comwrote in message
news:c3**********************************@f13g2000 hsa.googlegroups.com...
for(int i = 1; i< = arr.Length - 1; i ++)
for (int i = 1; i <= arr.Length - 1; i++)
如果使用会发生什么:
for(int i = 0; i< arr。长度; i ++)
-
Mark Rae
ASP.NET MVP
http://www.markrae.net
What happens if you use:
for (int i = 0; i < arr.Length; i++)
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
嗨。
感谢您的回复。
我收到了InxedOutOfBoundsException :
for(int i = 1; i< = arr.Length; i ++)
{
if(arr [i]!="")< ---在这里例外,在哪里
i = 4
{
当前范围是:
[0]""
[1]犹他州
[2]杰克逊
[3] Climbing.wmv
Hi.
Thanks for responding.
I get an "InxedOutOfBoundsException" :
for (int i = 1; i <= arr.Length; i++)
{
if (arr[i] != "") < --- EXCEPTION THROWN HERE, WHERE
i = 4
{
The Current Range is:
[0] ""
[1] "Utah"
[2] "Jackson"
[3] "Climbing.wmv"
" pbd22" < du ***** @ gmail.com写信息
新闻:22 ************************* ********* @ e4g2000h sg.googlegroups.com ...
"pbd22" <du*****@gmail.comwrote in message
news:22**********************************@e4g2000h sg.googlegroups.com...
感谢您的回复。
我得到一个InxedOutOfBoundsException :
for(int i = 1; i< = arr.Length; i ++)
Thanks for responding.
I get an "InxedOutOfBoundsException" :
for (int i = 1; i <= arr.Length; i++)
最大的尊重,如果你真的尝试了代码我会发生什么?建议b $ b ... ...
-
Mark Rae
ASP.NET MVP
http://www.markrae.net
With the greatest of respect, what happens if you actually try the code I
suggested...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
这篇关于凌乱的TreeView结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!