Yes, this tutorial is VERY good. Read it, absolutely.
A few notes which came to my mind when reading the questions
but i want to change text of items?
i use this code to set text item:
FormMain.TV_T3_1.ItemS[0].Text := Str1
VirtualTreeView is called "virtual" because it does not contain any data. It is just the container for a hierarchical relationship between nodes. Data are provided by means of events or external data structures. Therefore you cannot change the Text in an item, you must change the text in the associated data structure.
Also, in above code snipped, you are referencing nodes by means their index. This is possible, yes, but it is a very ineffecient way. Better to follow the parent-child-sibling relationships. The VST provides methods for finding all these nodes for a given node.
how can i count of items?
What do you mean as "count"? Count of the children of a node (--> VST.ChildCount[node]), Count of the children and all their children etc (--> node^.TotalCount), count of all nodes in the tree (--> VST.TotalCount); node is a PVirtualNode here, e.g. VST.FocusedNode. I am not 100% sure about this, but I think normally the tree does not even know how many nodes it has in total because it would have to open all nodes. But this is just the reason for the speed of VST: it loads only the nodes when they are needed, and querying the count would require the tree to load all nodes. Since the VST can handle with millions if nodes, this would be very inefficient. Do you really need the Count?
how can i set fouce or select , item 'n' ?
Again: what is "n"? Of all nodes? Or the index within the children of a given node? But better to stop thinking of n, better think of the nodes directly, that's the way the tree is designed. If you mean the n-th node in the top level, e.g. you can do this to find the node (not tested..):
function FindNthTopLevelNode(VST: TVirtualStringTree; n: Integer): PVirtualNode);
begin
Result := VST.GetFirstChild(VST.RootNode);
while (n > 0) and (Result <> nil) do begin
Result := VST.GetNextSibling(Result);
dec(n);
end;
end;
Once you found the node you can select/focus it this way
var node: PVirtualNode;
VST.FocusedNode := node;
VST.Selected[node] := true; // both needed!
how can i get text of selected item??
You must get the data associated with the selected node. The data are a user-defined structure, usually a record or a class, and you know how to retrieve the text from it. Assuming that data are a record as defined in the tutorial then you can do this:
type
PTreeData = ^TTreeData;
TTreeData = record
Column0: String;
Column1: String;
Column2: String;
end;
function GetNodeText(VST: TVirtualStringTree; ANode: PVirtualNode): String;
var
data: PTreeData;
begin
data :=PTreeData( VST.GetNodeData(ANode));
if data = nil then
Result := ''
else
Result := data^.Column0;
end;
etc, etc.
Trying to use the VirtualStringTree requires a steep learning curve. It is much more than just reading a short forum answer. I urge you to read the tutorial recommended in the previous post. You may also seek for more in the internet, e.g.
https://www.youtube.com/watch?v=o6FpUJhEeoY.