Solved

Set one dataset filter

Posted on 1998-03-19
10
166 Views
Last Modified: 2010-04-06
Hello ALL,

I need to setup the filter property of one dataset in the run time.
I want to select between three values:
catg = 'p'
catg = 'c'
catg = 'o'
Where:                   catg is the field name in the dataset (ttable),
                   p,c and o are the values I want to select.
I'm using one TRadioGroup to select and:

case TRadioGroup.ItemIndex of
0 : '????????'; { set catg = 'p'}
1 : '????????'; { set catg = 'c'}
2 : '????????'; { set catg = 'o'}
end;

The code I'm using doesn't works. Any suggestion?

Regards....
0
Comment
Question by:sergio_2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360622
What is the Exact Coding ?
the code you have given is not real code
is it like below
(note double-single quotes)

case TRadioGroup.ItemIndex of
0: DateSet.Filter := ' catg = ''p'' ';
0: DateSet.Filter := ' catg = ''c'' ';
0: DateSet.Filter := ' catg = ''o'' ';

Have you set the DataSet.Filtered to True

RCJ
0
 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360623
should be
case TRadioGroup.ItemIndex of
0: DateSet.Filter := ' catg = ''p'' ';
1: DateSet.Filter := ' catg = ''c'' ';
2: DateSet.Filter := ' catg = ''o'' ';

RCJ
0
 

Expert Comment

by:bijoyn
ID: 1360624
Hi There,

I am putting up an e.g. that I tried out. It has a radiogroup with option as 'Active' and 'InActive'. I have a datasource and a Query component on the form. There is a field called 'ActiveInd' which can have values 'Y' or 'N'. what I do is onclick of a button, I set the filter property to 'Y' or 'N' depending on the radio item selected and open the query. The results are shown in a DBGrid.

--------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, DBCtrls, DB, DBTables, ExtCtrls, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DataSource2: TDataSource;
    Query2: TQuery;
    DBGrid1: TDBGrid;
    RadioGroup1: TRadioGroup;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
   Query2.Filter  := '';
   Query2.Close;
   if RadioGroup1.ItemIndex = 0 then
      Query2.Filter  := 'ACTIVEIND = ' + '''' + 'Y' + ''''
   else
      Query2.Filter  := 'ACTIVEIND = ' + '''' + 'N' + '''';
   Query2.Open;
end;

end.

-------------------------------

I hope this helps.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1360625
Oops didn't saw already that much people had given an answer :

Heck here is my answer :

Put a table, datasource, dbgrid and radiogroup on the form
Put values MED, HIGH, LOW in the radiogroup.
Take DBDEMOS as Database and  Clients.DBF as table.

Link table to datasource and datasource to grid. copy this example to your unit and run!

click on the radiogroup and see the results.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Grids, DBGrids, DB, DBTables;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    RadioGroup1: TRadioGroup;
    procedure RadioGroup1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
  0 : Table1.Filter := 'Risk_Level = ''MED''';
  1 : Table1.Filter := 'Risk_Level = ''HIGH''';
  2 : Table1.Filter := 'Risk_Level = ''LOW''';
 end;
  showmessage(Table1.Filter);
 Table1.Filtered := True;
end;

end.


Bye,
Regards, Zif.
0
 

Author Comment

by:sergio_2001
ID: 1360626
Hi All,

I'll evaluate all answers...
How can select just one correct answer ???

Thanks....
0
 
LVL 1

Expert Comment

by:RJENKINS
ID: 1360627
Ask that person to submit their comment as an answer
and then award the points to them
0
 

Expert Comment

by:bijoyn
ID: 1360628
Hi Sergio,

Which of the solutions are working for u ???

Bijoy
0
 

Author Comment

by:sergio_2001
ID: 1360629
Hi all,

Both bijoyn and ZifNab answer works. However ZifNab's answer is more easy to use.
So send me the answer.

Thanks...
0
 

Author Comment

by:sergio_2001
ID: 1360630
One correction,

RJENKINS answer I suppose works too. There are some confusion with the quotation marks. And his answer was the first one. So please send me the answer.

Thanks...

0
 
LVL 1

Accepted Solution

by:
RJENKINS earned 20 total points
ID: 1360631
Try code like below

case TRadioGroup.ItemIndex of
  0: DateSet.Filter := ' catg = ''p'' ';
  1: DateSet.Filter := ' catg = ''c'' ';
  2: DateSet.Filter := ' catg = ''o'' ';
end;
Set the DataSet.Filtered to True

RCJ
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question