Delphi中ListView中实现自定义删除功能的方法
第一种:有时删除文件会出现文件删不掉现象
if lvMain.InnerListView.ItemIndex <> -1 then
begin
// DoContextMenuVerb(lvMain.SelectedFolder, ‘delete‘);
DoContextMenuVerbB(lvMain.Folders[lvMain.InnerListView.ItemIndex],
‘delete‘);
第二种:删除功能很强大,建议使用第二种
Item := SelectMain.Selected;
filename := Item.SubItems.Strings[3];
if DirectoryExists(filename) then
begin
oldroot := tvMain.Root.CustomPath;
DeleteDir(filename + ‘\‘);
if not DirectoryExists(filename) then
Item.Delete;
end
else
begin
DeleteDir(filename);
if not FileExists(filename) then
Item.Delete;
end;
时间: 2024-12-22 07:08:11