Working With TreeListView Control
I believe, that when you begin the work with treelistview the first action which you carry out it simply expanding or collapsing displayed treelistview. Therefore let’s consider two elementary functions carrying out these actions.
This two functions are quite simple and i think you don’t need any comments about them.
Before we will continue, investigate object TreeListView through the Object Browser. You will see that all nodes in the TreeListView are represented by a Nodes property – compound property which can contain other Nodes. Each Nodes property has Count property which contains number of its child nodes and Item property for working with each child node. So if we need to get any child node of the TreeListView we should call get_Items method for TreeListView object and then call get_Item method with index of the wanted node.
Let’s consider one of most often used by me functions: TreeListView_GetFullPathByIndex and TreeListView_GetNodeIndexByPath. I use function TreeListView_GetFullPathByIndex when it is necessary for me to receive the Full Path of Node and when I precisely know an index of this node. When it is necessary for me to receive a node index, and I know precisely full path for this node then I I use TreeListView_GetFullPathByIndex. Below you can find a code for these functions:.
As you could be convinced having seen a previous code, in these functions also there is nothing difficult. So let’s continue.
Now we will consider the elementary example of how to check up Node presence in a tree. The function presented by me below has two parameters: a tree view object and an item to be looked for. The symbol “” is used as separator between nodes.
Next function is designed to select node with the specified fullpath. To make node selected we need to change Selected property to true, but sometimes it is not enough so we addtitionally perform a user click on the node using ClickItem(int) method.
And at last, below you can find a code of function which perform double click on node with specified full path. The most useful method within this function is DblClickItem (int) which allows you to perform doble-click action.
This is all. I hope, that this article will help those from you who will face in the work with TreeListVew. Best Regards, Artem Rudenko