delphirowhighlightingtdbgrid

DBGrid Highlighting the located row via code?


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.


Solution

  • OK, After I tried myself, then I findout that the code below can do the code :

    DBGrid1.setfocus;
    

    Since the row already correctly selected, the setfocus help the highlight to come up.

    Anyway, thanks for the replies :)