filter stringgrid on keyword(s)

Hi

I have a stringgrid with populated data.
I wish to filter using keywords e.g. KW1,KW2

e.g.
row 1,col1: blue and red plate
row 2:col1: red cup
row 3:col1: pink glass

If i search for KW1 = 'blue'  or  KW2 = 'glass'

I want row 1 and row 3 to show after filtering

How to do this?

here is my code:
---------------------------------------------------------------
if KW1 <> '' then
Begin
  with ProductFindFrm.SGSearch.Filter.Add do
  begin
    condition := QuotedStr('='+KW1+'');
    column := 1;
  end;
end;

if KW2 <> '' then
Begin
  with ProductFindFrm.SGSearch.Filter.Add do
  begin
    condition := QuotedStr('!'+KW2+'
');
    column := 1;
  end;
end;

ProductFindFrm.SGSearch.ApplyFilter;
------------------------------------------------------------------

Regards

Kamran

Try to change your code to:


if KW1 <> '' then
Begin
  with ProductFindFrm.SGSearch.Filter.Add do
  begin
    condition := QuotedStr('='+KW1+'');
    column := 1;
  end;
end;

if KW2 <> '' then
Begin
  with ProductFindFrm.SGSearch.Filter.Add do
  begin
    condition := QuotedStr('!'+KW2+'
');
    column := 1;
    if ProductFindFrm.SGSearch.Filter.Count > 1 then  
      operation := foOR;
  end;
end;


Hi

Thanks for that.

However the filter only picks up the first word token of the row.
if the keyword comes after the first word in the row then it does not select it !

Is that how it is supposed to be ?

e.g.
row 1,col1 =  "blue and red plate"
row 2:col1 =  "red cup"
row 3:col1 =  "pink glass"

If i search for KW1 = 'blue'  or  KW2 = 'glass'

I want row 1 and row 3 to show after filtering
(note that the word glass is the second word in row 3.)

Thanks

Kamran

With this filter, it returns row 1 and 3:


var
  fd: TFilterData;
begin
  advstringgrid1.Filter.Clear;

  fd := advstringgrid1.Filter.Add;
  fd.Column := 1;
  fd.Condition := 'blue';

  fd := advstringgrid1.Filter.Add;
  fd.Column := 1;
  fd.Condition := 'glass';
  fd.Operation := foOR;

  advstringgrid1.FilterActive := true;
end;

Hi Bruno

That works !

I misunderstood the usage of multiple condition operators with multiple search words.

Thank you.

Kamran