et focus to DBGrid for editing

Posted in Components

Use SetFocus method and EditorMode property of DBGrid. Also, you need to send EM_SETSEL message.

procedure TForm1.Button1Click(Sender: TObject);
var
  CurrentWindowFocus: THandle;
begin
  DbGrid1.SetFocus;
  DbGrid1.EditorMode:=True;
  CurrentWindowFocus:=Windows.GetFocus;
  SendMessage(CurrentWindowFocus, EM_SETSEL, 0, 0);
end;