Im using delphi's ttreeview as an 'options' menu. how would i go upon selecting the next node at runtime like a previous and next button? i tried the getprev and getnext methods but no luck.
+5
A:
Here you have the 'Next' behavior. For 'Previous' I leave as exercise for you: :-)
procedure TForm8.btn1Click(Sender: TObject);
var
crt: TTreeNode;
begin
with tv1 do //this is our tree
begin
if Selected=nil then
crt:=Items[0] //the first one
else
crt:=Selected.GetNext; //for previous you'll have 'GetPrev'
if crt<>nil then //can be 'nil' if we reached to the end
Selected:=crt;
end;
end;
HTH
+1
A:
Maybe there is some space in tree item to store pointer to you correct page.
But - if you have some time - try to explore Virtual Treeview - it's Delphi's best treeview component.
DiGi
2008-10-06 22:16:31
A:
here is another way to do this:
type TfrmMain = class(TForm)
...
public
DLLHandle : THandle;
function GetNodePath(node: TTreeNode; delimiter: string = '\') : String;
...
function TfrmMain.GetNodePath(node: TTreeNode; delimiter: string = '\') : String;
begin
Result:='';
while Assigned(node) do
begin
Result:=delimiter+node.Text+Result;
node:=node.Parent;
end;
if Result <> '' then
Delete(Result, 1, 1);
end;
...
here is how to use it: on your treeview's click or doubleclick event do this
...
var
path : String;
begin
path:=GetNodePath(yourTreeView.Selected);
ShowMessage(path);
...
if you have a 'Item 1' and a subitem called 'Item 1' and click on Item 2 than the message should be 'Item 1\Item 2'. By doing this you can have a better control...
hope this gives you another idea to enhance your code
Remus Rigo
2010-06-03 18:58:05