How to set FilterBar in Edit Value and Apply Filter ?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
eta
Posts: 7
Joined: Wed 25 Oct 2017 14:06
Location: Turkey, Istanbul
Contact:

How to set FilterBar in Edit Value and Apply Filter ?

Post by eta » Mon 11 Dec 2017 08:34

We are using SDAC (8.0.3) component with C++ Builder 6.
We want to set FilterBar in Edit value of TCRDBGrid as programmatically.
We're tried following code:

Code: Select all

  DBGrid->ActivateFilterEdit(DBGrid->Columns->Items[4]);

  TComponent* component;
  TCRGridTitleEdit* CRGridTitleEdit;
  int count = DBGrid->ComponentCount;
  for (int i=0; i < count; i++)
  {
     component = DBGrid->Components[i];
     CRGridTitleEdit =  dynamic_cast<TCRGridTitleEdit*>(component);
     if (CRGridTitleEdit)
     {
       //CRGridTitleEdit->Edit->OnKeyDown(CRGridTitleEdit->Edit, VK_RETURN, TShiftState() );
       CRGridTitleEdit->Edit->OnKeyDown(CRGridTitleEdit->Edit, VK_RETURN, TShiftState() );

       CRGridTitleEdit->EditingFilter = true;
       CRGridTitleEdit->StartEdit();
       CRGridTitleEdit->Edit->Modified = true;

       CRGridTitleEdit->Edit->Text = "FİLTER TEXT*";
       CRGridTitleEdit->Edit->OnChange(CRGridTitleEdit->Edit);
       break;
     }
  }

  DBGrid->Filtered = true;
But does not work above code and Edit value is automatically clearing.
How to fix this problem ?
Thanks for support.

eta
Posts: 7
Joined: Wed 25 Oct 2017 14:06
Location: Turkey, Istanbul
Contact:

Re: How to set FilterBar in Edit Value and Apply Filter ?

Post by eta » Mon 11 Dec 2017 11:40

We're solved problem with below code.

Code: Select all

  DBGrid->ActivateFilterEdit(DBGrid->Columns->Items[4]);

  TComponent* component;
  TCRGridTitleEdit* CRGridTitleEdit;
  int count = DBGrid->ComponentCount;
  for (int i=0; i < count; i++)
  {
     component = DBGrid->Components[i];
     CRGridTitleEdit =  dynamic_cast<TCRGridTitleEdit*>(component);
     if (CRGridTitleEdit)
     {
       CRGridTitleEdit->StartEdit();
       CRGridTitleEdit->EditingFilter = true;
       CRGridTitleEdit->Edit->Text = "NAK*";
       CRGridTitleEdit->Edit->Modified = true;
       CRGridTitleEdit->EditingFilter = false;
       break;
     }
  }
  DBGrid->ApplyFilter();

Stellar
Devart Team
Posts: 122
Joined: Tue 03 Oct 2017 11:00

Re: How to set FilterBar in Edit Value and Apply Filter ?

Post by Stellar » Mon 11 Dec 2017 15:24

You can activate the filter programmatically and set the value exactly as you described

Post Reply