Hello,
Is there a way to do a filter in the DBGrid component using a part of a field or fields? For example, the following code only finds one record in which the contents of the field "DESC_LIN_1" matches the exactly what is typed in the TEdit Component.
procedure TfrmCPItemFile.edtKeywordKeyPress(Sender: TObject; var Key: Char);
var
myFilterString : string;
begin
if ord(Key) <> 8 then
myFilterEntry := myFilterEntry + StringOfChar(Key, 1)
else
myFilterEntry := AnsiMidStr(myFilterEntry, 1, length(myFilterEntry)-1);
myFilterString := 'DESC_LIN_1 = ' + CHR(39) + myFilterEntry + CHR(39);
DataModuleUnit.ADOtblITEM.Filter := myFilterString;
DataModuleUnit.ADOtblITEM.Filtered := true;
end;
What we would like to accomplish is the DBGrid component listing all records that meet a partial match between the contents of the TEdit and the contents of the "DESC_LIN_1" and "DESC_LIN_2" fields. In addition, we do not want case sensitivity to play a factor in the filtering.
Therefore, if "Helm" is typed in the TEdit component then we would like it to display the records in which "DESC_LIN_1" field has "Red Helmet" or "DESC_LIN_2" has "HELMET".
Regards,
Georges
Is there a way to do a filter in the DBGrid component using a part of a field or fields? For example, the following code only finds one record in which the contents of the field "DESC_LIN_1" matches the exactly what is typed in the TEdit Component.
procedure TfrmCPItemFile.edtKeywordKeyPress(Sender: TObject; var Key: Char);
var
myFilterString : string;
begin
if ord(Key) <> 8 then
myFilterEntry := myFilterEntry + StringOfChar(Key, 1)
else
myFilterEntry := AnsiMidStr(myFilterEntry, 1, length(myFilterEntry)-1);
myFilterString := 'DESC_LIN_1 = ' + CHR(39) + myFilterEntry + CHR(39);
DataModuleUnit.ADOtblITEM.Filter := myFilterString;
DataModuleUnit.ADOtblITEM.Filtered := true;
end;
What we would like to accomplish is the DBGrid component listing all records that meet a partial match between the contents of the TEdit and the contents of the "DESC_LIN_1" and "DESC_LIN_2" fields. In addition, we do not want case sensitivity to play a factor in the filtering.
Therefore, if "Helm" is typed in the TEdit component then we would like it to display the records in which "DESC_LIN_1" field has "Red Helmet" or "DESC_LIN_2" has "HELMET".
Regards,
Georges