ComponentOne FlexGrid for WinForms
C1.Win.C1FlexGrid Namespace / Node Class
Members Example

In This Topic
    Node Class
    In This Topic
    The Node class encapsulates properties and methods used for manipulating node rows (collapsing, expanding, moving, and sorting them).
    Object Model
    Node ClassNode ClassNode ClassNode ClassNode ClassNode ClassNode ClassNode ClassNode ClassNode ClassNode ClassRow Class
    Syntax
    'Declaration
     
    
    Public Class Node 
    public class Node 
    Remarks

    Node rows are used to group regular rows that contain similar data. These can be created using the Subtotal method of C1FlexGridBase class or by using the GroupDescriptions property or by setting the IsNode property to true for certain rows. Rows.InsertNode method can also be used to insert a new node row at a specified index. These rows can be expanded or collapsed to display/hide the regular rows in each group.  
    This class represents such node rows and helps in manipulating these rows in the following ways:

    • Create a node row at a specified position relative to a node with the help of AddNode method.
    • Remove a node row and all its child rows (nodes and data) from the grid using the RemoveNode method.
    • Use the Move method to move a node row to a new position. Moving of node rows is supported when the grid is in unbound mode.
    • Selection of a node is possible with the help of the Select method.
    • Sorts a node's child nodes with the help of Sort method. This method is supported only when the grid is in unbound mode.
    • Get or set the data or image on a node row at the column that contains the outline tree using the Data and Image properties respectively.
    • Use the Row property to get a reference to the Row object that corresponds to a node.
    • Get the parent node of a node with the help of Parent property.
    • Retrieve the count of child nodes under a node with the help of Children property. And you can get an array containing the children of a node using its Nodes property.
    • Get or set whether a node is collapsed or expanded through the Collapsed and Expanded properties.
    • Get the first child node or the last child node using FirstChild and LastChild properties.
    • Use FirstSibling and LastSibling properties to get the first sibling node or the last sibling node.
    • Determine whether any child of node is visible using the HasVisibleChildren property.
    • You can specifically get the first visible child node using the FirstVisibleChild property and  get the next visible sibling node or the previous visible sibling node through the NextVisibleNode and PrevVisibleNode properties.
    • Get or set the outline level for a node using the Level property.
    • Get or set the checkbox value associated with a node using its Checked property.
    Example
    private void Form1_Load(object sender, EventArgs e)
    {
                _flex = new C1FlexGrid();
                _flex.Bounds = new System.Drawing.Rectangle(60,80,400,500);
                this.Controls.Add(_flex);
    
                _flex.Cols.Fixed = 0;
                _flex.Cols.Count = 1;
                _flex.Rows.Count = 1;
                _flex.ExtendLastCol = true;
                _flex.Tree.Column = 0;
                // Populate the grid.
                AddDirectory(@"c:\\", 0);
    }
    
    private void AddDirectory(string dir, int level)
    {
                // add this directory.
                string thisDir = Path.GetFileName(dir);
                if (thisDir.Length == 0) { thisDir = dir; }
                _flex.Rows.Add();
    
                //make this new row a node
                Row row = _flex.Rows[_flex.Rows.Count - 1];
                row.IsNode = true;
    
                //set node level
                Node nd = row.Node;
                nd.Data = thisDir;
                nd.Level = level;
                // add files in this directory.
                int cnt = 0;
                Row r;
                foreach (string file in Directory.GetFiles(dir))
                {
                    _flex.Rows.Add();
                    //mark the row without child row as node
                    r = _flex.Rows[_flex.Rows.Count - 1];
                    r.IsNode = true;
                    Node node = r.Node;
                    node.Data = Path.GetFileName(file).ToLower();
                    node.Level = level + 1;
                    cnt = cnt + 1;
                    if (cnt > 10) break;
                }
    
                // add subdirectories (up to level 4).
                if (level <= 4)
                {
                    cnt = 0;
                    foreach (string subdir in Directory.GetDirectories(dir))
                    {
                        AddDirectory(subdir, level + 1);
                        cnt = cnt + 1;
                        if (cnt > 10) break;
                    }
                }
    }
    
    private void sortNodeAsc_Click(object sender, EventArgs e)
    {
                //Sorts the selected node in Ascending Order
                Node node = _flex.Rows[_flex.Row].Node;
                node.Sort(SortFlags.Ascending);
    }
    
    private void sortNodeDesc_Click(object sender, EventArgs e)
    {
                //Sorts the selected node in Descending Order
                Node node = _flex.Rows[_flex.Row].Node;
                node.Sort(SortFlags.Descending);
    }
    Inheritance Hierarchy

    System.Object
       C1.Win.C1FlexGrid.Node

    See Also