i m trying to build an invoice program that holds data in an Access db. i have some tedit s, buttons, one datasource, one adotable, one dbgrid and a popup menu. database format is accdb.
Problem: i want the program to filter records while user is typing. it might filter dbgrid or tedit, doesn t matter. i somehow found some code, for example:
Table1.开发者_如何学编程FilterOptions:=[foCaseInsensitive];
Table1.Filter:='Filmadi='+QuotedStr(Edit1.Text+'*');
Table1.Filtered:=true;
the code above gives this error: Project Project1.exe raised exception class eoleexception with message: Item cannot be found in the collection corresponding to the requested name or ordinal
other examples give various errors.
sincerely onurUse LIKE operator in your filter:
procedure DoIncrementalFilter(Dataset: TDataSet; const FieldName, SearchTerm: string);
begin
Assert(Assigned(Dataset), 'No dataset is assigned');
if SearchTerm = '' then
Dataset.Filtered := False
else
begin
Dataset.Filter := FieldName + ' LIKE ' + QuotedStr(SearchTerm + '*');
Dataset.Filtered := True;
end;
end;
Example:
DoIncrementalFilter(ADOTable1, 'Filmadi', Edit1.Text);
精彩评论