TShellListView 创建新文件夹并重命名它

问题描述 投票:0回答:3

我正在 Delphi 中开发一个项目,我有

TShellListView
组件(列表),以及用于创建新文件夹的按钮:

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

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

我该怎么做?

delphi delphi-10-seattle
3个回答
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;

0
投票

我找到了解决方案:

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;

0
投票

无法与新文件夹和编辑标题同时进行此工作,尝试了 list.update 和 list.refresh 但没有达到所需的效果,对于它有效的现有文件夹。最终在表单上放置一个计时器(10毫秒),并在创建文件夹期间将其打开timer.enable。计时器事件处理编辑标题并自行切换。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.