Ilyes
Ilyes

Reputation: 14928

TShellListView create new folder & rename it

Im working on a project in Delphi , I have TShellListView component (List) ,and Button to create New folder :

MkDir(List.RootFolder.PathName+'\New Folder');
List.Update;

But what I need is when the user create the new folder, then then the folder automatically show in edit mode, so he can change the folder name, as when you create New Folder in Windows.

How can I do that?

Upvotes: -2

Views: 615

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597896

Try something like this:

var
  Path, PathName: string;
  Folder: TShellFolder;
  I: Integer;
begin
  Path := IncludeTrailingPathDelimiter(List.RootFolder.PathName) + 'New Folder';
  if not CreateDir(Path) then Exit;
  List.Refresh;
  for I := 0 to List.Items.Count-1 do
  begin
    Folder := List.Folders[I];
    if (Folder <> nil) and (Folder.PathName = Path) then
    begin
      List.Items[I].EditCaption;
      Exit;
    end;
  end;
end;

Alternatively:

var
  Path: string;
  Item: TListItem;
begin
  Path := IncludeTrailingPathDelimiter(List.RootFolder.PathName) + 'New Folder';
  if not CreateDir(Path) then Exit;
  List.Refresh;
  Item := List.FindCaption(0, 'New Folder', False, True, False);
  if Item <> nil then
    Item.EditCaption;
end;

Upvotes: 1

Ilyes
Ilyes

Reputation: 14928

I found a solution:

MkDir(List.RootFolder.PathName+'\New Folder');
List.Update;
List.ItemIndex:=0;
List.HideSelection:=True;
while List.ItemIndex<List.Items.Count-1 do
begin
  // Find the New Folder 
  if List.SelectedFolder.PathName=(List.RootFolder.PathName+ '\New Folder') then
  begin
    //Set the Folder in Edit mode & exit the loop
    List.Items[List.ItemIndex].EditCaption;
    Exit;
  end
  else
    //Inc the Index
    List.ItemIndex := List.ItemIndex+1;
end;
List.HideSelection:=False;

Upvotes: 0

Related Questions