Winform TreeView to find the next node

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/Ruiky/archive/2013/02/01/2888674.html

public static class Treeviewhelper {private static ienumerable<treenode> childNodes (this TreeNode node) {return node.} Nodes.cast<treenode> ().        SelectMany (x = X.selfandchildnodes ()); } private static Ienumerable<treenode> selfandchildnodes (this TreeNode node) {return new List<treenode> () {node}. Union (node. Nodes.cast<treenode> ().        SelectMany (x = X.selfandchildnodes ()));  } private static Ienumerable<treenode> nextnodes (this TreeView tree, TreeNode node) {bool            after = false; if (node. Parent = = null) return to tree. Nodes.cast<treenode> (). Select (x = {bool b = after = after | | (node = = x); Return new {x, b}; })                           . Where (x = x.b && x.x! = node). SelectMany (x = NEW list<treenode> () {x.x}.            Union (X.x.childnodes ())); else return node. Parent.nodes.cast<treenode> (). Select (x = {bool b = after = after | | (node = = x); Return new {x, b}; })                           . Where (x = x.b && x.x! = node). SelectMany (x = new list<treenode> () {x.x}. Union (X.x.childnodes ())). Union (Tree.nextnodes (node.        Parent)); } public static ienumerable<treenode> nextnodes (this TreeView tree, TreeNode node) {if (t REE = = NULL | |            node = = null) return new list<treenode> (); Return Node.childnodes ().        Union (Tree.nextnodes (node));  public static ienumerable<treenode> Nextnodes (this TreeView tree) {if (tree = = NULL | | Tree.            SelectedNode = = null) return new list<treenode> (); Return tree. Nextnodes (tree.SelectedNode); }    }

  

How to Invoke:

var tn = _tv.nextnodes (). FirstOrDefault (x = Regex.IsMatch (X.text, "(? i)" + TxtKey.Text.Trim ()));

if (tn = = NULL)

MessageBox.Show ("Find complete");

Else

_tv.selectednode = TN;

public static ienumerable<treenode> Treewhere (this treenodecollection TDs, Func<treenode, bool> fun)        {            foreach (TreeNode item in TDS)            {                if (item)                    yield return item;                var list = Item. Nodes.treewhere (fun);                foreach (var item1 in list)                    yield return item1;            }        }

How to Invoke:

var tn = treeView1.Nodes.TreeWhere (x = Regex.IsMatch (X.text, @ "(? i)" + TxtKey.Text.Trim ()));

Category: C#,winform

Winform TreeView to find the next node

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.