Formatting TreeNode FullPath

  • Thread starter Thread starter _asgar
  • Start date Start date
A

_asgar

Guest
I am formatting the FullPath property of the TreeNode. I want to add a indexer to each path separated by "/".

e.g root/item1[2]/item2[1]/item3[3].The problem is the indexer moves to the left e:g root[2]/item1[1]/item2[3]/item3

private void fpath(TreeNode tn, ref string path,int l)
{
int pos = path.LastIndexOf('/', l); ;
int index = -1;
if (tn.Text == "root") return;
else
{
foreach (TreeNode n in tn.Parent.Nodes)
{

if (n.Text == tn.Text) index++;

if (n == tn && pos != -1)
{
path = path.Insert(pos, "[" + (index + 1).ToString() + "]");
}

l -= (tn.Text.Length - 1);
}

fpath(tn.Parent, ref path,l);

}

}

and iam caalling it like this

string path = treeView1.SelectedNode.FullPath;
fpath(treeView1.SelectedNode, ref path,path.Length -1);





Asgar

Continue reading...
 
Back
Top