Goin' crazy with this recursive function ported from delphi...
I send a string like DirA/ DirB /DirC but i get in the treeView
each one in a new node.Cant get the child node....!!
-DirA
-DirB
-DirC
instead of:
DirA
|
- DirB
|
-DirC
Could anyone have a look of this code?.Thanks.
There'a listarray to store the path to avoid double nodes(dont works).
private void LoadNode(string path)
{
string s;
int p,ix;
if (path != "")
{s=path;
}
else
{
s="<EmptyPath>" ;
}
p=myAL1.IndexOf (s);
if(p >= 0)
{
treeView1.Nodes .Add(myAL1[p].ToString());
}
else
{
p=-1;
//find pos of final separator
string Del = @"\";
for (ix=s.Length-1;ix >=0;ix--)
{
int answer = System.String.C ompare(s[ix].ToString(),Del );
string mm=s[ix].ToString();
if (answer==0)
{
p=ix;
break;
}
}
if (p< 0)
{
node= null;
}
else
{
LoadNode(s.Subs tring(0,p));
s=s.Substring(p ,s.Length-p);
}
treeView1.Nodes .Add(s);
treeView1.Selec tedNode=node;
myAL1.Add(s);
}
}
I send a string like DirA/ DirB /DirC but i get in the treeView
each one in a new node.Cant get the child node....!!
-DirA
-DirB
-DirC
instead of:
DirA
|
- DirB
|
-DirC
Could anyone have a look of this code?.Thanks.
There'a listarray to store the path to avoid double nodes(dont works).
private void LoadNode(string path)
{
string s;
int p,ix;
if (path != "")
{s=path;
}
else
{
s="<EmptyPath>" ;
}
p=myAL1.IndexOf (s);
if(p >= 0)
{
treeView1.Nodes .Add(myAL1[p].ToString());
}
else
{
p=-1;
//find pos of final separator
string Del = @"\";
for (ix=s.Length-1;ix >=0;ix--)
{
int answer = System.String.C ompare(s[ix].ToString(),Del );
string mm=s[ix].ToString();
if (answer==0)
{
p=ix;
break;
}
}
if (p< 0)
{
node= null;
}
else
{
LoadNode(s.Subs tring(0,p));
s=s.Substring(p ,s.Length-p);
}
treeView1.Nodes .Add(s);
treeView1.Selec tedNode=node;
myAL1.Add(s);
}
}
Comment