I have one tree view in my windows form. I use the following function to select the node in that treeView.
private void FindAndSelect(TreeNodeCollection collection, object toSelect)
{
//problem in this line becouse while converting the toSelect into IstructuredEntity is showing null.
var entityToSelect = toSelect as Decoupling::IStructureEntity;
if (entityToSelect == null) //just select the Structure root
{
_treeView.SelectedNode = _treeView.Nodes[0];
return;
}
foreach (TreeNode tn in collection)
{
var treeNodeEntity = tn.Tag as IStructureEntity;
if (treeNodeEntity != null && treeNodeEntity.Id == entityToSelect.Id)
{
_treeView.SelectedNode = tn;
}
FindAndSelect(tn.Nodes, toSelect);
}
}
But the above function is only able to select the parent node in treeView and I want to select and highlight the child. Can anyone please guide me as to what I need to change for this to work?