delphidelphi-10-seattle

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?


Solution

  • 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;