如何实现根据TreeView的Tag来实现代码式的选中

无聊的一个人啊 2009-11-30 04:33:47
比如我们知道了一个节点的Tag=1012
我们怎么通过代码选中那个Tag
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不好意思自己已经解决了,呵呵,谢谢
goto_code 2009-11-30
  • 打赏
  • 举报
回复
首先要遍历所有节点,判断tag是否相符,相符的就选中
以下是我从数据库中遍历显示所有treeview并添加的代码
你需要稍加修改,参数string strValue是tag

private TreeNode fun_FindNode(TreeNode tnParent, string strValue, TreeNode tnc)
{
//遍历TV
if (tnParent == null)
return null;
if (tnParent.Tag.ToString() == strValue)
{
tnParent.Nodes.Add(tnc);//这里改成treeview1.SelectedNode = tnParent;
return tnParent;
}
TreeNode tnRet = null;
foreach (TreeNode tn in tnParent.Nodes)
{
tnRet = fun_FindNode(tn, strValue, tnc);
if (tnRet != null)
{
break;
}
}
return tnRet;
}

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧