求WPF中遍历treeview中所有节点的方法,谢谢。是wpf中
解决方案 »
- 怎么把字典集合数据绑定到DataGridView中
- 求一个计算人民币面值组合的算法
- 如何将MATLAB中的M文件转换成C#中可调用的DLL文件
- 右对齐问题
- 通过win服务在局域网其它机器上,创建目录出现System.UnauthorizedAccessException异常
- 请问:C#中创建线程时,线程调用的函数里面如何含参数呢?
- 关于C# 拨号程序(多分奉送)
- 请问一个dataset中fill几个数据表时就会出错,怎么解决啊!
- 关于 ASP.NET 中submit的问题
- 调试时候出的问题,怪呀怪呀怪,实在不明白是怎么回事,微软专家能进来看看吗
- C#使用IrisSkin2.dll控件的问题,急...
- 在应使用条件的上下文(在'|1|'附近)中指定了非布尔类型的表达式!求高手进来解答!!!
{
if (td.ToolTipText == selectParentNum)
{
return td;
}
TreeNode targetNode = null;
foreach (TreeNode childNodes in td.Nodes)
{
targetNode = SearchNode(childNodes, selectParentNum);
if (targetNode != null)
break;
}
return targetNode;
}
private void CheckNodes(IList<String> fidList)
{
//检验tvw_Function是否有内容
if (0 == tvw_Function.Nodes.Count)
{
Exception ex = new Exception("tvw_Function has no content!");
StackTrace st = new StackTrace(new StackFrame(true));
StackFrame sf = st.GetFrame(0);
Tool.WriteLog(true , ex , st , sf);
return;
} TreeNode tnRoot , tnCurrent , tnCurrentPar;
tnRoot = tvw_Function.Nodes["root"];
tnCurrentPar = tnRoot;
tnCurrent = tnCurrentPar.FirstNode; //遍历tvw_Function获取被勾选的节点信息
while (tnCurrent != null && tnCurrent != tnRoot)
{
while (tnCurrent != null)
{
//若当前节点功能的fid在fidList之中,则将其勾选
if (null != tnCurrent.Tag)
if (null != fidList.FirstOrDefault(fid => fid == ((FunctionInfo) tnCurrent.Tag).fid))
{
tnCurrent.Checked = true;
tnCurrent.ForeColor = Color.Salmon;
} if (tnCurrent.Nodes.Count > 0)
{
//移动到下一层节点
tnCurrentPar = tnCurrent;
tnCurrent = tnCurrent.FirstNode;
}
else if (tnCurrent != tnCurrentPar.LastNode)
{
//移动到本层下一个节点
tnCurrent = tnCurrent.NextNode;
}
else
break;
} //逐层回溯父节点
while (tnCurrent != tnRoot && tnCurrent == tnCurrentPar.LastNode)
{
tnCurrent = tnCurrentPar;
tnCurrentPar = tnCurrentPar.Parent;
} //回溯停止后移动到本层下一个节点
if (tnCurrent != tnRoot)
tnCurrent = tnCurrent.NextNode;
}
}
在 Windows Form 应用中,我们碰到需要展开一个TreeView 控件的所有树节点的时候很简单,微软已经替我们提供了ExpandAll 方法,我们只要简单的一行代码tv_QTree.ExpandAll();就可以了。即 System.Windows.Forms 命名空间的 TreeView.ExpandAll 方法 。
在WPF中,我们会发现,System.Windows.Controls.TreeView 中没有了 ExpandAll 方法。唯一跟展开有关系的属性和方法就是每一个TreeViewItem 中有一个属性IsExpanded 属性。这个属性定义这个节点是否打开。MSDN帮助如下: Gets or sets whether the nested items in a TreeViewItem are expanded or collapsed. This is a dependency property. 这时候如何办呢? 很简单,自己写个递归,遍历这个树的每一个子节点,然后把每一个子节点的 IsExpanded 设置为 true.
详情:http://ghj1976.spaces.live.com/blog/cns!F5D0FA8B5536921!212.entry