example 1 : filter dropdown & popup menu per column
Using filtersEasy setup of filters for each column is possible with the TGridColumnItem.Filter property. This is a stringlist that can hold several predefined filters.
The format of the predefined filters in this stringlist is :
friendly filtername = filterspec
The friendly filtername can be any text that should be shown in the dropdown list for selection while the filterspec is the actual specifier for the filter.
The filterspecifier can be considered as a supercharged file filter specifier. It handles * and ? , it can handle larger than , less than and it can have or and and symbols.
The TGridColumnItem.FilterCaseSensitive determines if the filter should be handled with or without case sensitivity.
Examples : [All] = *
First half of alphabet = <M
Second half of alphabet = >M
All cars starting with A = A*
All cars starting with A or M = A* | M*
All cars starting between B and M = >B & <M
As soon as at least one filter is in the filter list, the filter dropdown button the header of the column is displayed.
The appearance of this dropdown list is controlled by the Grid.FilterDropDown property :
Grid.FilterDropDown has following properties:
Color : sets the background color of the dropdown list
ColumnWidth : when true, the dropdown list automatically uses the column width of the current selected column
Font : sets the font of the list
Width : sets the width of the dropdown list unless ColumnWidth = true
Height : sets the height of the dropdown list
When all this is in place, there is not much more to do. The TAdvColumnGrid is ready to handle all the filtering.
Note that when multiple columns have filters, the rows displayed are a result of a logical AND of all filters in use.
An additional capability is to specify a filter that is queried or set at run-time.
This can be handled with the OnFilterSelect event. This event is triggered upon mouse or keyboard selection of a filter from the dropdownlist.
The filter itemindex, friendlyname and filter specifier are returned. As the filterspecifier : FilterCondition is a variable parameter in this event, it can be changed easily at runtime like in the example below :
procedure TForm1.AdvColumnGrid1FilterSelect(Sender: TObject;
Column, ItemIndex: Integer; FriendlyName: string; var
if FriendlyName = '[Custom]' then
Using popup menusThe new version of TAdvColumnGrid also simplifies handling of popup menus to control various aspects of the grid.
A popup menu can be assigned to each grid's Column and it can be specified on which mouse key & location the popup menu should be displayed.
This can be left or right mouse click on column header cells only, normal cells only or all cells in column. When the popup menu is about to be displayed, the OnColumnPopup event is triggered returning the cell where the mouse click that caused the popup happened.
This value can be used in the event handlers of the popup menu itself to perform column or cell specific actions. The sample below makes this clear to use the popup menu to do column specific sorts.
// grid's OnColumnPopup event handler
procedure TForm1.AdvColumnGrid1ColumnPopup(Sender: TObject; ACol,
ARow: Integer; PopupMenu: TPopupMenu);
AdvColumnGrid1.SortSettings.Column := ACol;
// popup menuitems event handler
procedure TForm1.SortascendingClick(Sender: TObject);
AdvColumnGrid1.SortSettings.Direction := sdAscending;
// popup menuitems event handler
procedure TForm1.SortdescendingClick(Sender: TObject);
AdvColumnGrid1.SortSettings.Direction := sdDescending;
The project and source files have been written with Delphi 6. To use these files in other versions of Delphi, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the Delphi 6 form file, but not available in lower versions of Delphi
Copyright © 1995 - 2015 TMS Software v4.0