TShellListView创建新文件夹&重命名

时间:2017-01-13 17:16:12

标签: delphi delphi-10-seattle

我在Delphi中处理项目,我有TShellListView组件(List),而Button用于创建新文件夹:

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

但我需要的是当用户创建新文件夹,然后文件夹自动以编辑模式显示,这样他就可以更改文件夹名称,就像在Windows中创建新文件夹一样。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:

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;

可替换地:

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;

答案 1 :(得分:0)

我找到了解决方案:

recursiveCall(0);