如何实现根据TreeView的Tag来实现代码式的选中 比如我们知道了一个节点的Tag=1012我们怎么通过代码选中那个Tag 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先要遍历所有节点,判断tag是否相符,相符的就选中以下是我从数据库中遍历显示所有treeview并添加的代码你需要稍加修改,参数string strValue是tagprivate 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; } C#如何获取cookie 怎么用XMl和C#动态显示导航栏,根据不同权限显示不同导航栏 关于"相等"的疑问:引用类型/值类型/特殊的String/==/ReferenceEquals/ 存储过程的问题 取值的方法 关于vs2010专业版,工具箱添加组件,求帮忙解答! 各位大侠,请问如何调用子窗体的一些变量啊? C# 获取收件箱邮件列表问题 SSL using Word; 这条语句编译都出错?!不懂! 报表运行时根据参数 显示 某些列怎么做?救命呵,在线等待; 求一个用c#编写的一款手机浏览器源代码 【不知道怎么入手】C# 如何实现 HTMl 页面打印【初次学习】
以下是我从数据库中遍历显示所有treeview并添加的代码
你需要稍加修改,参数string strValue是tagprivate 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;
}