在TreeView控件中获取节点. [英] Getting the nodes in a TreeView control.

查看:64
本文介绍了在TreeView控件中获取节点.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个树状视图,它包含数百个节点,其中许多是缩进的.例如,以资源管理器视图为例.声明:

int i = ExampleTreeView.GetNodeCount(true);

返回示例树视图中所有节点的计数.我尝试过搜索单线,但是如果树视图可以告诉您有多少个节点,是否有一种方法可以返回这些节点的扁平化"列表暨数组,也可以作为单线语句返回?

我已经看到了许多使用递归来构建扁平节点列表的示例,但是框架中可能有一些可以为我做的事情吗?我想认为该框架可能有一些功能,但是如果我必须使用递归进行操作,那就照做吧.

有谁知道框架中会为我做的事情吗?

I''ve got a treeview on a form and it contains a few hundred nodes, many indented. Think of the explorer view for example. This statement:

int i = ExampleTreeView.GetNodeCount(true);

returns the count of all the nodes in my example treeview. I''ve tried searching for a one-liner but if the treeview can tell you how many nodes there are, is there a method that will return a "flattened" list-cum-array of those nodes, also as one-liner statement?

I''ve seen lots of examples that use recursion to build a flattened list of nodes but maybe there''s something in the framework that''ll do it for me? I''d like to think the framework might have something but if I have to do it with recursion, then so be it.

Does anyone know of something builtin to the framework that''ll do that for me?

推荐答案

框架中没有任何东西可以将节点的分层树转换为平面清单:无法确定是否可以区分不同的元素:
There is nothing in the framework that will convert a hierarchical tree of nodes into a flat list: it could not be sure that it would be possible to distingiush dfferent elements:
Root
  branch1
    leaf1
    leaf2
  branch2
    leaf1
    leaf2  

默认的平面视图将只有四个元素,两个元素称为"leaf1",两个元素称为"leaf2".

您将需要递归解析树.

A default flat view would have only four elements, two called "leaf1" and two called "leaf2".

You will have to recursively parse the tree.


这篇关于在TreeView控件中获取节点.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆