Sorry, the explanation is not clear. The behaviour you describe is already available in AdvDirectoryTreeView. It first loads all directories (for example with AdvDirectoryTreeView.LoadDrives or AdvDirectoryTreeView.LoadDirectory) and then when clicking the expand node, the sub folders are dynamically loaded. Please explain more in detail what exactly it is that you want to achieve?
You can use GetCurrentDir for knowing the last dir the user has opened:
You will have to write your own loop then, and cast the node to TAdvDirectoryTreeViewNode. After casting you can use the FileName property to see if the directory matches the one the user has last used. Other than that approach, there is no magic solution unfortunately.
Yes, you can with this code:
type
TAdvDirectoryTreeViewOpen = class(TAdvDirectoryTreeView);
procedure TForm1.FormCreate(Sender: TObject);
begin
AdvDirectoryTreeView1.LoadDrives(False);
TAdvDirectoryTreeViewOpen(AdvDirectoryTreeView1).AddSubNodes(AdvDirectoryTreeView1.Nodes[0]);
AdvDirectoryTreeView1.Nodes[0].Expand;
end;
var
i: Integer;
nd: TAdvTreeViewNode;
mynode, mychild: TAdvDirectoryTreeViewNode;
s: String;
basedrive: String;
found: Boolean;
begin
if aFolder = '' then
Exit;
basedrive := ExtractFileDrive(aFolder);
found := False;
// Loop over nodes to find the correct one if there
for i := 0 to tvFileList.Nodes.count - 1 do
begin
mynode := TAdvDirectoryTreeViewNode(tvFileList.Nodes);
s := mynode.filename;
if Uppercase(ExtractFileDrive(s)) = Uppercase(basedrive) then
begin
// Load & Expand node
TAdvDirectoryTreeViewOpen(tvFileList).AddSubNodes(mynode);
mynode.Expand;
mychild := TAdvDirectoryTreeViewNode(mynode.getnext);
repeat
if mychild <> NIL then
begin
s := mychild.filename;
// found final path node?
if Uppercase(ExtractFilePath(s)) = Uppercase(aFolder) then
begin
TAdvDirectoryTreeViewOpen(tvFileList).AddSubNodes(mychild);
tvFileList.SelectNode(mychild);
mychild.Expand;
Exit;
end;
// is correct path
if Copy(aFolder, 1, length(s)) = s then
begin
TAdvDirectoryTreeViewOpen(tvFileList).AddSubNodes(mychild);
mychild.Expand;
mychild := TAdvDirectoryTreeViewNode(tvFileList.GetFirstChildNode(mychild));
end
Else
mychild := TAdvDirectoryTreeViewNode(mychild.getnext);
end;
until (mychild = NIL);
end;
end;
end;