I got the : ADOTable1 ( codepeople as integer, namepeople as string ) DataSource1 ( the DateSet is ADOTable1 ) DBGrid1 ( connected to DataSource1, Options-dgRowSelect is true )
I locate a row on ADOTable1 with the following code
ADOTable1.Locate(ADOTable11codepeople.FieldName, 1, []);
DBGrid1 is selecting the correct row. But not with the highlights.
How to make the DBGrid automatically highlights the row that I located from ADOTable1 ?
I read the following links and did not find the answer :
How to set active cell in TDBGrid?
Delphi - Using DBGrid to select rows from a search
View position in DBGrid when scrolling in Delphi
Simple source code please...
PS: I use Delphi 2010.
The following code will cause the selected row in a grid to be highlighted
type
THackDBGrid = class (TDBGrid);
...
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if (THackDBGrid(dbGrid1).DataLink.ActiveRecord + 1 = THackDBGrid(dbGrid1).Row)
or (gdFocused in State) or (gdSelected in State) then
dbGrid1.canvas.Brush.Color:= clMoneyGreen;
dbGrid1.DefaultDrawColumnCell (Rect, DataCol, Column, State);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With