PRODUCTS

FEATURED PRODUCT

Office 2007 ribbon bar or Office 2003 toolbar & menus for your Windows applications

License only 75 EUR See More

SEARCH

LOGIN

Customer login to access products, support information & special benefits.

NEWS ALERTS

Add your e-mail address here to receive the monthly TMS Software alerts.

 

LINKS

EXAMPLE 22

TAdvStringGrid

example 22 : Using filtering

TAdvStringGrid

With the new filtering capabilities in TAdvStringGrid, displaying a selection of the grid's data is easier than ever. Two properties are used for filtering. First there is the FilterData property, which is a TCollection of filter conditions for each column and second is the property FilterActive through which filtering is performed when set true.

Taking a closer look at the FilterDate collection, this is a TCollection of elements with 2 properties, Condition, which is a string and Column which is an integer. The Condition property can contain a condition in following formats :

substring filterting : S*, S? : * or ? denote multi or single character matches >, < , >=, =< : larger than, less than, larger or equal, less or equal (when data is numeric, comparison take place based on numeric data, otherwise on alphabetic comparisons) = , ! : equal or not equal & , ^ : logical AND , logical OR

Thus, an expression : >20 & <30 is a valid filtering expression as well as !A*

In this example, the conditions are set by clicking on the column header and specifying the condition for each column. This is done with the OnClickCell event:

procedure TForm1.AdvStringGrid1ClickCell(Sender: TObject; Arow, Acol: Integer);
var
   s:string;
begin
  if (arow=0) and (acol>0) then
  begin
    s := AdvStringGrid1.Cells[acol,arow];
    if InputQuery('Column ' + IntToStr(acol),'Condition',s) then
      AdvStringGrid1.Cells[acol,arow] := s;
  end;
end;

When the Apply filter button is clicked, the FilterData collection is built from these conditions and FilterActive is set true :

procedure TForm1.CheckBox1Click(Sender: TObject);
var
  i:integer;
begin
  with advstringgrid1 do
  begin
    filteractive:=false;
    filter.Clear;
    for i:=fixedcols to colcount-1 do
    begin
      if (cells[i,0]<>'') then
      with filter.add do
      begin
        condition := Cells[i,0];
        column:= i;
      end;
    end;
    filteractive := True;
  end;
end;


Delphi project & source files for downloading included in the main demos distribution for Delphi.

The project and source files have been written with Delphi 6,7. 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 - 2008 TMS Software