Good afternoon to all,
i have a strange situation with filter conditions.
In my grid i try to filter for all rows that have the value in col 5 empty ('') but with this code the grid will not be filtered:
procedure TFIMZG.CHK1Click(Sender: TObject);
begin
SG1.FilterActive:=False;
SG1.Filter.Clear;
if CHK1.Checked then
begin
with SG1.Filter.Add do
begin
Column:=5;
Condition:='<>' + QuotedStr('');
end;
SG1.FilterActive:=True;
end;
end;
Due the fact that in column 5 is stored a string rappresenting the date, i tried also with (the empty cells could have value zero)
Condition := '= 0';
In this case the grid is totaly empty, all rows are "cleared" .... included header (not formatted)
With any other value the filter work properly ....
All the rows with empty cell in column 5 is alway showed.
where i wrong ??
Actualy i resolve the problem setting the empity cells (alias no date information) to the 30/12/1899 and setting the filter condition with
with SG1.Filter.Add do
begin
Column:=5;
Condition := '= 30/12/1899';
end;
and it works, but seems to be a dirty solution ....
Thanks for all
Regard
Daniele
PS : The filter works on the dispalyed cell text setted with GetDisplText event.
This event help us to display the text according our need, in this circustance we need to have the choice to apply the filter to the original text or the changed one.
I have recheched this here and I cannot see an issue to define a filter to retain empty cells in a given column.
Test code:
Hi Bruno,
thank's for reply.
I made some test and i got for same previous conditions (empty cell value):
A - The filter work for
Condition:='= ' or Condition:=' "" ' (Where " is shift 2)
In both cases the grid shows only empty cells
B - The filter does not work for
Condition:='= ' + QuotedStr('');
Condition:='= '''' '; (Where '''' are 4 times ' )
This colud be possible due the fact in Unit AdvUnit in function:
function MatchStr(s1,s2:string;DoCase:Boolean):Boolean;
the the first code line is
if s1 = '""' then // (2 times shift 2)
MatchStr := (s2 = '')
and work only with A
but if i change the first line with
if (s1 = '""') or (s1=QuotedStr('')) then
MatchStr := (s2 = '')
this work with any condition for empty cells:
Condition:='= '
Condition:='= '''' ' (Two times shift 2 or 4 time ')
Condition:='= ' + quotedStr('');
Of course, this on my pcs.
Bruno, thank's for all
Regards
Daniele
After the equal sign, there should be the value, so for empty strings, please set the condition to: