System.Windows.Forms.TreeNodeCollection.Contains C# (CSharp) Method

Contains() public method

public Contains ( TreeNode node ) : bool
node TreeNode
return bool
        public bool Contains(TreeNode node)
        {
            return this.IndexOf(node) != -1;
        }

Usage Example

        public static TreeNode FindNextNode( TreeNodeCollection nodes, TreeNode selected )
        {
            if( nodes != null && nodes.Count > 0 )
              {
            TreeNode node1 = ( selected == null ) ? nodes[0] : selected;
            TreeNode backup = node1;

            if( node1.Nodes.Count > 0 ) // if we have child the show it first
            {
              return node1.Nodes[0];
            }
            else
            {
              TreeNode node2 = node1;

              while( node2 != null )
              {
            if( node2.Parent == null || nodes.Contains( node2 ) == true ) // if we on the top of tree
            {
              if( node2.Index < nodes.Count-1 ) // check can we select next node or not
              {
                return nodes[ node2.Index + 1 ];
              }
              else // we on the last node in tree
              {
                // if we on last child of tree node
                if( node2 != backup ) return backup;

                return node2;
              }
            }
            else // if we have a parent node
            {
              node1 = node2.Parent;

              if( node2.Index < node1.Nodes.Count-1 ) // can we select next node
              {
                return node1.Nodes[ node2.Index + 1 ];
              }
              else // go to the parent
              {
                node2 = node1;
              }
            }
              }
            }
              }

              return null;
        }
All Usage Examples Of System.Windows.Forms.TreeNodeCollection::Contains