How to select the first child node of a treeview.

G

Guest

I've tried the following, but keep getting the error "Object reference not
set to an instance of the object."

TreeNode node = tvHistory.Nodes[0].FirstNode;
tvHistory.SelectedNode = node;

I've also tried:
tvHistory.SelectedNode = tvHistory.Nodes[0].FirstNode;

Any suggestions?
 
G

Guest

I found the solution.

I had to put tvHistory.Select() just prior to activate the treeview.
So it now looks like:
sHistory.Select();
sHistory.SelectedNode = sHistory.Nodes[0].Nodes[0];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top