QuantumGrid - como montar filtro via programacao cxGrid |
Top Previous Next |
|
My users can set a filter for the Grid via the popup lists of column headers or using the custom filter dialogs. I want to give them the ability to use predefined filters. How can I perform the same operations in code?
Solution
To set up a filer programmatically, it's necessary to use the AddItem and AddItemList methods of the Data Controller's filter criterion.
The following example demonstrates how to set filter criteria for the following string:
(CustNo < 1000) AND ((Name LIKE 'A%') OR (Name LIKE 'Z%')).
The colCustNo and colName objects are of the TcxGridDBColumn class. They identify the desired columns in a View.
To prevent the filter criteria from being updated every time a filter condition is added, operations are enclosed within the TcxFilterCriteria.BeginUpdate and TcxFilterCriteria.EndUpdate methods.
[Delphi]
var AItemList: TcxFilterCriteriaItemList; ... <DataController>.Filter.BeginUpdate; try <DataController>.Filter.Root.Clear; <DataController>.Filter.Root.AddItem(colCustNo, foLess, 1000, '1000'); AItemList := <DataController>.Filter.Root.AddItemList(fboOr); AItemList.AddItemcolName, foLike, 'A%', 'A%'); AItemList.AddItem(colName, foLike, 'Z%', 'Z%'); finally <DataController>.Filter.EndUpdate; end; |