Tips and Frequently Asked Questions

Auto filtering in a grid with dynamically formatted cell values based on real cell values
Suppose a grid filled with numbers loaded from a database for example but these numbers are dynamically formatted via the OnGetDisplText event. If we want to perform auto filtering via a filter dropdown, the filtering typically needs to be performed on the real cell data and not the formatted cell text. In this case, the formatting that is done is to add a currency suffix €. In the filter condition we also want to display the currency suffix but we still want the filtering to be applied on the real cell value with real value filter conditions.
The grid is filled with randome numbers between 0 and 100 and the formatting is applied via OnGetDisplText to append the currency suffix €:
procedure TForm1.FormCreate(Sender: TObject);
begin
advstringgrid1.RandomFill(false);
advstringgrid1.FilterDropDownCheck := true;
end;
procedure TForm1.AdvStringGrid1GetDisplText(Sender: TObject; ACol,
ARow: Integer; var Value: string);
begin
if (arow > 0) and (acol > 0) then
Value := Value +''€'';
end;
The filter dropdown is filled with 3 conditions and these conditions include the currency suffix:
procedure TForm1.AdvStringGrid1GetColumnFilter(Sender: TObject; Column: Integer;
Filter: TStrings);
begin
Filter.Add(''>10€ & <20€'');
Filter.Add(''>20€ & <50€'');
Filter.Add(''>50€'');
end;
First thing that needs to be done is set the real filter condition based on numbers only from the OnFilterCheck event:
procedure TForm1.AdvStringGrid1FilterCheck(Sender: TObject; Column, ItemIndex: Integer; FriendlyName: string; var FilterCondition: string; CheckList: TCheckListBox); begin // caption := inttostr(advstringgrid1.Filter.Count); case ItemIndex of 0: FilterCondition := ''>10 & <20''; 1: FilterCondition := ''>20 & <50''; 2: FilterCondition := ''>50''; end; end;
Then we need to instruct for the filter condition to take the real cell value and not the formatted value in account:
This can be done in two ways in the OnBeforeFilter event that is triggered when the filter conditions are all built-up and just before these will be applied. Either set the filter instructions to use the real grid value or to specify the suffix:
Method 1:
procedure TForm1.AdvStringGrid1BeforeFilter(Sender: TObject);
var
i:integer;
begin
for i := 0 to advstringgrid1.Filter.Count - 1 do
advstringgrid1.Filter.Items[i].Data := fcNormal;
end;
Method 2:
procedure TForm1.AdvStringGrid1BeforeFilter(Sender: TObject);
var
i:integer;
begin
for i := 0 to advstringgrid1.Filter.Count - 1 do
advstringgrid1.Filter.Items[i].Suffix := ''€'';
end;
Pricing
Single Developer License
Small Team License
Site License
TMS VCL UI Pack
€ 395
€
175
yearly renewal
license for 1 developer
Includes
check
Full source code
check
Access to the TMS Support Center
check
Free updates and new releases
MOST POPULAR
TMS VCL Subscription
€ 895
€
450
for a 2 year renewal
license for 1 developer
Includes
check
Full source code
check
Access to the TMS Support Center
check
Free updates and new releases
check
TMS VCL UI Pack
check
All TMS VCL products
more_horiz
Discover more
BEST VALUE
TMS ALL-ACCESS
€ 1,795
€
595
yearly renewal
license for 1 developer
Includes
check
Full source code
check
Access to the TMS Support Center
check
Free updates and new releases
check
TMS VCL UI Pack
check
All TMS VCL products
check
All TMS products
more_horiz
Discover more
All prices excl. VAT. Renewal price is subject to change and only valid up to 30 days after license has expired. After renewal period a discount price is offered to renew the license.
Free Trial
Start a free TMS VCL UI Pack evaluation today!Please enter a valid email address
Download started. Your trial key will be provided by email!
By entering your email address you agree to receive email messages from TMS Software.
Note that the TMS VCL UI Pack replaces the TMS Component Pack. Both products can't be installed simultaneously. Therefore TMS Component Pack must first be uninstalled before installing the TMS VCL UI Pack