Open / save file dialog set focus to the file list view

2.2k Views Asked by At

is it possible to open TOpenDialog, TSaveDialog with focus set to the file list view instead of file name edit box ?

Thanks a lot

Regards

1

There are 1 best solutions below

5
On BEST ANSWER

You can put the focus to the control you like but the dialog should be ready when you do that. The 'OnShow' event is early for that. You can use 'OnFolderChange' event for instance, together with a flag in order to not to change the focus every time the folder is changed:

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure OpenDialog1FolderChange(Sender: TObject);
  private
    FDlgSetFocus: Boolean;

uses
  dlgs;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDlgSetFocus := False;
  OpenDialog1.Execute;
end;

procedure TForm1.OpenDialog1FolderChange(Sender: TObject);
begin
  if not FDlgSetFocus then
    windows.SetFocus(GetDlgItem(GetParent((Sender as TOpenDialog).Handle), lst2));
  FDlgSetFocus := True;
end;