Reputation: 1
I have delphi 7.
I want to search for data inside a dbgrid
That I have linked to excel using a adotable and a data source.
I have searched the internet and only found how to create a new excel document or how to link the excel document
But I want to search the first column through all the rows
Upvotes: 0
Views: 4791
Reputation: 1
while not adoquery1.Eof do
begin
for I := 0 to adoquery1.FieldCount-1 do
if (enhdbgrid1.Fields[i].value<>null) and (pos(uppercase(edit1.Text),uppercase(enhdbgrid1.Fields[i].Value))>0) then
begin
Found := True;
enhDBGrid1.SelectedField := enhdbgrid1.Fields[i];
Break;
end;
if found then break;
adoquery1.Next;
end;
Upvotes: 0
Reputation: 371
Yes, the Locate is the better choice. Your DBGrid is linked to a ClientDataSet or Query, use de Locate on your DataSource.
MyClientDataSet.Locate( .... For more details, on your delphi code, select the word Locate and with F1 open you help inside delphi.
Upvotes: 0
Reputation: 3996
Once the Excel is loaded into the ADOTable, it is just like any other ordinary table.
Better do not search in the grid. Instead, use the Locate
method of your AdoTable for this.
//or using [loCaseInsensitive,loPartialKey] options
ADOTable1.Locate('FieldName', 'Value', []);
You might want to use DisableControls
and EnableControls
to avoid the grid refreshing graphically while you locate the values you need, and a bookmark to return to the original position.
HTH
Upvotes: 2