TreeList.PopulateColumns() Method
Creates columns for all public fields in the bound data source.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.2.dll
Declaration
Remarks
The TreeList automatically calls the PopulateColumns
method once you bind it to a data source. This behavior is specified by the AutoPopulateColumns option. Disable this option and manually call the PopulateColumns
method to create columns when needed.
The PopulateColumns
method clears the TreeList’s Columns collection, creates columns for all public fields in a data source, and initializes column settings (FieldName, Caption, VisibleIndex ).
The PopulateColumns
method has no effect in unbound mode.
Note
The PopulateColumns
method does not create columns for service fields in the data source. Enable the TreeList’s PopulateServiceColumns option to create columns that are bound to Key, Parent, and Image fields specified by the KeyFieldName, ParentFieldName, and ImageIndexFieldName properties.
You can also create columns, customize their settings, and add them to the TreeList.Columns collection.
Example
The following example demonstrates how to create TreeList columns on button click.
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
// Forces the Tree List to initialize its settings.
treeList1.ForceInitialize();
// Disables the 'AutoPopulateColumn' option.
treeList1.OptionsBehavior.AutoPopulateColumns = false;
// Configures the Tree List and binds it to data.
treeList1.KeyFieldName = "ID";
treeList1.ParentFieldName = "ParentID";
treeList1.DataSource = NodeObject.InitNodes();
}
private void populateColsButton_Click(object sender, EventArgs e) {
// Creates columns for all public fields in the bound data source.
treeList1.PopulateColumns();
// Expands all nodes.
treeList1.ExpandAll();
}
}
public class NodeObject {
public int ID { get; set; }
public int ParentID { get; set; }
public string ValueA { get; set; }
public string ValueB { get; set; }
static public List<NodeObject> InitNodes() {
return new List<NodeObject>() {
new NodeObject() { ID = 0,ParentID = 0, ValueA = "Value A-1", ValueB = "Value B-1" },
new NodeObject() { ID = 1,ParentID = 0, ValueA = "Value A-1-0", ValueB = "Value B-1-0" },
new NodeObject() { ID = 2,ParentID = 1, ValueA = "Value A-2-1", ValueB = "Value B-2-1" },
new NodeObject() { ID = 3,ParentID = 2, ValueA = "Value A-3-2", ValueB = "Value B-3-2" },
new NodeObject() { ID = 4,ParentID = 2, ValueA = "Value A-4-2", ValueB = "Value B-4-2" }
};
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the PopulateColumns() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.