Edit this page

Setting Filters Programmatically

RadVirtualGrid includes FilterDescriptors property which stores filter descriptors used for filtering operation. The most important classes are:

  • FilterDescriptor: Implements filtering property (field) name, filtering operator and value. Used to define simple filtering expressions like Country = "Germany".

  • CompositeFilterDescriptor: A collection of multiple filter descriptors with logical operator. Used to define complex filtering expressions like (Country = "Germany" AND (City = "Berlin" OR City = "Aachen")) .


Before proceeding with this article, please refer to the Filtering Overview article which demonstrates how to achieve the filtering functionality in RadVirtualGrid.

Simple descriptors

FilterDescriptor's major properties:

  • PropertyName: defines the field, which values will be filtered.

  • Operator: allows you to define the type of operator. The possible values are: Contains, Does not contain, Starts with, Ends with, Equals, Not equal to, Is null, Is not null.

  • Value: the value your data will be compared against.

When you add a new descriptor to the collection, the data is automatically filtered according to it.

virtualgrid-setting-filters-programmatically 001

Using simple filter descriptor

FilterDescriptor filter = new FilterDescriptor();
filter.PropertyName = "ContactName";
filter.Operator = FilterOperator.StartsWith ;
filter.Value = "p";
filter.IsFilterEditor = true;

Dim filter As New FilterDescriptor()
filter.PropertyName = "ContactName"
filter.[Operator] = FilterOperator.StartsWith
filter.Value = "p"
filter.IsFilterEditor = True

Composite descriptors

To filter a single data field by multiple values, you have to use the CompositeFilterDescriptor object. It contains a collection of filter descriptors objects and the logical operator for that filters.

virtualgrid-setting-filters-programmatically 002

Using CompositeFilterDescriptor

CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
compositeFilter.FilterDescriptors.Add(new FilterDescriptor("ContactName", FilterOperator.StartsWith,"p"));
compositeFilter.FilterDescriptors.First().IsFilterEditor = true;
compositeFilter.FilterDescriptors.Add(new FilterDescriptor("CompanyName", FilterOperator.Contains, "w"));
compositeFilter.LogicalOperator = FilterLogicalOperator.And;

Dim compositeFilter As New CompositeFilterDescriptor()
compositeFilter.FilterDescriptors.Add(New FilterDescriptor("ContactName", FilterOperator.StartsWith, "p"))
compositeFilter.FilterDescriptors.First().IsFilterEditor = True
compositeFilter.FilterDescriptors.Add(New FilterDescriptor("CompanyName", FilterOperator.Contains, "w"))
compositeFilter.LogicalOperator = FilterLogicalOperator.[And]

See Also