G
Guest
I have finally developed some code that allows you to re populate a tree view
and re select the last node that was clicked. However, you have to hard code
it for the number of levels the tree view could possibly be expanded to. Any
ideas?
//The test program has a button to set the path and a button to execute the
path finding code.
//This is so that you can close the treeview back up to the root to ensure
the correct code is selected
string delimit = @"\";
char [] delimiter = delimit.ToCharArray();
string [] split = null;
split = path.Split( delimiter );
int CountUnderRoot = treeView1.Nodes[0].Nodes.Count ;
if( split.Length > 1 )
{
for( int i =0; i<CountUnderRoot; i++)
{
if(treeView1.Nodes[0].Nodes.Text == split[1].ToString())
{
Debug.WriteLine("yes");
int countUnderLevel1 = treeView1.Nodes[0].Nodes.Nodes.Count;
if( countUnderLevel1 > 0 && split.Length == 3 )
{
for( int j =0; j<countUnderLevel1; j++)
{
if(treeView1.Nodes[0].Nodes.Nodes[j].Text == split[2].ToString())
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0].Nodes.Nodes[j];
break;
}
}
}
else
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0].Nodes;
break;
}
}
}
}
else
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0];
}
and re select the last node that was clicked. However, you have to hard code
it for the number of levels the tree view could possibly be expanded to. Any
ideas?
//The test program has a button to set the path and a button to execute the
path finding code.
//This is so that you can close the treeview back up to the root to ensure
the correct code is selected
string delimit = @"\";
char [] delimiter = delimit.ToCharArray();
string [] split = null;
split = path.Split( delimiter );
int CountUnderRoot = treeView1.Nodes[0].Nodes.Count ;
if( split.Length > 1 )
{
for( int i =0; i<CountUnderRoot; i++)
{
if(treeView1.Nodes[0].Nodes.Text == split[1].ToString())
{
Debug.WriteLine("yes");
int countUnderLevel1 = treeView1.Nodes[0].Nodes.Nodes.Count;
if( countUnderLevel1 > 0 && split.Length == 3 )
{
for( int j =0; j<countUnderLevel1; j++)
{
if(treeView1.Nodes[0].Nodes.Nodes[j].Text == split[2].ToString())
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0].Nodes.Nodes[j];
break;
}
}
}
else
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0].Nodes;
break;
}
}
}
}
else
{
treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[0];
}