![](/img/trans.png)
[英]Get/Set TShellListView Path/Folder as String (Not Using .Root)
[英]TShellListView create new folder & rename it
我在 Delphi 中處理一個項目,我有TShellListView
組件(列表)和用於創建新文件夾的按鈕:
MkDir(List.RootFolder.PathName+'\New Folder');
List.Update;
但是我需要的是當用戶創建新文件夾時,然后該文件夾會自動顯示為編輯模式,因此他可以更改文件夾名稱,就像您在 Windows 中創建新文件夾一樣。
我怎樣才能做到這一點?
嘗試這樣的事情:
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;
我找到了一個解決方案:
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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.