Column filtration

35 views
Skip to first unread message

Roman Cervenan

unread,
Nov 18, 2024, 3:26:14 AM11/18/24
to Rosi Delphi Components
Hello,
I have a question - I use rDBGrid this way:
  OptionsEx2.Filters.TextBar := True;
  OptionsEx2.Filters.FunnelBtn := False;
  OptionsEx2.Filters.MultiFieldFilter := True;
  OptionsEx2.Filters.FilterPanel := True;
Whole rDBGrid is in readonly mode.

I'm looking for this functionalities:
 - when focus is on some data cell and user starts typing (in standard DBGrid it is onKeyPress) I want to change focus to filter's TextBar above actual column and insert already typed character there - see my onKeyPress with standard DBGrid (and separate FiltrEdit object above column):

procedure TChooseFrm.DataDbGridKeyPress(Sender: TObject;
  var Key: Char);
begin
  case ord(key) of
    13: OKBitBtn.Click;
    27: CancelBitBtn.Click;
  else
    FiltrEdit.SetFocus;
    FiltrEdit.Text := key;
    FiltrEdit.SelStart := 2;
  end;
end;

And another - I want to save actual colum data filter (even when is filtered through more columns) and after reopening form with rDBGrid I need to fill corresponding TextBars with the same filter data again (set the same filtration with possibility to edit them in textbars - I know I can do this by filling FilterPanel, but it is for more experienced users).

Is this possible to do with rDBGrid?
Thanks for answer,
Roman

Tomas Rosinsky

unread,
Nov 18, 2024, 3:36:32 PM11/18/24
to Rosi Delphi Components
Hello,

you can easilly show text filter and enter pressed key by following code:

procedure TrDBGrid1.gr1KeyPress(Sender: TObject; var Key: Char);
begin
  if not CharInSet(Key, [#8, #27]) then
  begin
    gr1.SetTextFilter(nil, Key, false);
    Key:=#0;
  end;
end;

It works only if automatic lookup implemented in rDBGrid is switched off by property LookupCondition := lcNever

Automatic saving and restoring of filters can be done by my PropSave components, see https://rosinsky.cz/delphi/property_saver.html 
You have to use TrDBGridsPropSave and set property StoreFilterSetting = true.
Then all filter setting set in runtime is stored and then automaticly restored.

You can test it in my DBDemo application which uses PropSave components.

I hope it helps
Tomas


Dne pondělí 18. listopadu 2024 v 9:26:14 UTC+1 uživatel romanc...@gmail.com napsal:
Reply all
Reply to author
Forward
0 new messages