D
David Elliott
Hi,
I have a Windows Explorer-like treeview that displays directories. After a
cut/paste operation, I want the treeview to display the folder where the
paste happened. But, I'm running into a problem following the assignment of
the selectednode in the treeview. Here's the relevant code:
// separate the node names
string [] split = mcurrentPath.Split(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name
foreach (string s in split)
{
if (currIndex == 0)
// we're on the top-most node
currNode = tvwDirectory.TopNode;
// search the current node's nodes for this text
foreach (TreeNode n in currNode.Nodes)
{
if (n.Text == s)
{
currNode = n;
break;
}
}
currIndex++;
}
tvwDirectory.BeginUpdate();
tvwDirectory.SelectedNode = null;
tvwDirectory.Nodes.Clear();
FilltreeView();
tvwDirectory.SelectedNode = currNode;
tvwDirectory.SelectedNode.Expand(); <-- this is where I blow up!
tvwDirectory.EndUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the
Expand() I get this error:
System.NullReferenceException: Object reference not set to an instance of
an object.
Any help will be most appreciated.
Thanks,
I have a Windows Explorer-like treeview that displays directories. After a
cut/paste operation, I want the treeview to display the folder where the
paste happened. But, I'm running into a problem following the assignment of
the selectednode in the treeview. Here's the relevant code:
// separate the node names
string [] split = mcurrentPath.Split(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name
foreach (string s in split)
{
if (currIndex == 0)
// we're on the top-most node
currNode = tvwDirectory.TopNode;
// search the current node's nodes for this text
foreach (TreeNode n in currNode.Nodes)
{
if (n.Text == s)
{
currNode = n;
break;
}
}
currIndex++;
}
tvwDirectory.BeginUpdate();
tvwDirectory.SelectedNode = null;
tvwDirectory.Nodes.Clear();
FilltreeView();
tvwDirectory.SelectedNode = currNode;
tvwDirectory.SelectedNode.Expand(); <-- this is where I blow up!
tvwDirectory.EndUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the
Expand() I get this error:
System.NullReferenceException: Object reference not set to an instance of
an object.
Any help will be most appreciated.
Thanks,