Topic: select newly created row in tablegrid

Hello Dmitry, MVD Team,

When you click 'new record' on a tablegrid, create a new record and click 'save', is it possible to automatically highlight the new row that has just been created when you return to the tablegrid?  At the moment, the highlight always stays on whatever row had been selected before the new record was created.

I have been trying to write something like form1.tablegrid1.selectedrow := last_insert_id('tablename')  but maybe this isn't the correct way to do it.

Thanks,  Derek.

Re: select newly created row in tablegrid

Hello,


Example:

var
    PrevAction: string;

procedure frmEmployee_OnShow (Sender: string; Action: string);
begin
    PrevAction := Action;
end;

procedure Form1_GridEmployees_OnChange (Sender: string);
begin
    if PrevAction = 'NewRecord' then
    begin
        PrevAction := '';
        Form1.GridEmployees.dbItemID := Last_Insert_id('employees');
        Form1.GridEmployees.ScrollToRow(Form1.GridEmployees.SelectedRow);
        Form1.GridEmployees.SetFocus;
    end;
end;

Also you can download example project

Post's attachments

Attachment icon Auto select new record in Grid.zip 77.68 kb, 566 downloads since 2015-03-23 

Dmitry.

Re: select newly created row in tablegrid

Hi Dmitry,
It works perfectly now.
Thanks as always for your help.
Derek.