Skip to main content

TreeList.DataSource Property

Gets or sets the data source for the current TreeList control.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.1.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

public object DataSource { get; set; }

Property Value

Type Description
Object

The data source object.

Remarks

You can bind all traditional data sources to the Tree List control: BindingSource, BindingList<T>, DataTable, DataView, IBindingList, IList, etc. In bound mode, the Tree List control creates nodes for all records in the data source at one time, when it loads data. It does not load data dynamically in this mode.

Because of the data source’s tree-like structure, the Tree List control implements a specific sorting algorithm. Therefore you cannot use the data source’s functionality in order to sort data. Use the XtraTreeList’s methods instead (for example, the TreeListColumn.SortOrder property).

The code sample below illustrates how to populate a tree list with random values.

treeList1.DataSource = CreateTLData(100);

DataTable CreateTLData(int recordCount)
{
    Random rnd = new Random();
    DataTable tbl = new DataTable();
    tbl.Columns.Add("ID", typeof(int));
    tbl.Columns.Add("ParentID", typeof(int));
    tbl.Columns.Add("Name", typeof(string));
    tbl.Columns.Add("Date", typeof(DateTime));
    tbl.Columns.Add("Checked", typeof(bool));
    for (int i = 0; i < recordCount; i++)
        tbl.Rows.Add(new object[] { i, rnd.Next(20), String.Format("Name{0}", i), DateTime.Now.Date.AddDays(rnd.Next(-250, 250)), rnd.Next(2) == 0 });
    return tbl;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

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.

See Also