TreeList.DataSource Property

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

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

Declaration

public object DataSource { get; set; }
Public Property DataSource As Object

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;
}
See Also