Filtering in Code

  • 2 minutes to read

To filter Tree List nodes in code, utilize the following API:

Note that disabling the TreeListOptionsCustomization.AllowFilter property prevents only your end-users from applying and changing Tree List filters at runtime. The filtering itself remains functional and you can still utilize all the mentioned APIs. Disable the TreeList.ActiveFilterEnabled setting to temporarily deactivate applied filters.

Example

The example below ensures that Tree List records with the 15% discount are always visible, regardless of the currently applied filtering condition.

TreeList - Custom Filter

private void TreeList1_CustomRowFilter(object sender, CustomRowFilterEventArgs e) {
    TreeList treeList = sender as TreeList;
    string discount = treeList.GetRowCellDisplayText(e.Node, treeList.Columns["Discount"]);
    if (discount == "15%") {
        e.Visible = true;
        e.Handled = true;
    }
}