TreeView for WinForms | ComponentOne
In This Topic
    TreeView Columns
    In This Topic

    There are two types of columns in the TreeView control, bound and unbound. In the unbound mode, a column is not bound to the fields of the data source and displays the string representation of the node. In the bound mode, a column obtains its data from the TreeView's data source and displays the underlying data.

    TreeView contains a single column by default. However, you can add multiple columns to the Columns collection of TreeView to use the control in different scenarios. For instance, you may want to present sales data of different regions for two consecutive years by using multiple columns.

    The control allows you to add columns easily at design-time with C1TreeColumn Collection Editor. Refer to Collection Editors for more information.

    To create columns through code, you need to create an instance of C1TreeColumn and add it to the Columns collection of C1TreeView. To remove all columns from the Columns collection of TreeView, you can use the Clear method of C1TreeColumnCollection. Also, you can remove the first occurrence of a specified column from the collection by using the Remove method that accepts the C1TreeColumn type instance as a parameter. And you can remove a column at the specified index by using the RemoveAt method that accepts the column index value of the Integer type as a parameter.

    The following code snippet creates a column, specifies its header and name, and adds the column to the Columns collection of TreeView.

    ' clear the Columns collection
    C1TreeView1.Columns.Clear()
    
    ' create a column
    Dim Column1 As New C1.Win.TreeView.C1TreeColumn()
    
    ' name the column header
    Column1.HeaderText = "Column1"
    
    ' name the column
    Column1.Name = "Column1"
    
    ' add the column to the Columns collection of TreeView
    C1TreeView1.Columns.Add(Column1)
    
    // clear the Columns collection
    c1TreeView1.Columns.Clear();
    
    // create a column
    C1.Win.TreeView.C1TreeColumn Column1 = new C1.Win.TreeView.C1TreeColumn();
    
    // name the column header
    Column1.HeaderText = "Column1";
    
    // name the column
    Column1.Name = "Column1";
    
    // add the column to the Columns collection of TreeView
    c1TreeView1.Columns.Add(Column1);