我的窗体中有一个树状视图。我使用以下函数来选择该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);
}
}
但是上面的函数只能在treeView中选择父节点,我想选择并突出显示子节点。 任何人都可以指导我为什么需要改变这个工作?