How do I manage items

To get rid of an item already in the tree, use the Delete(item) method, where the item parameter is the wx.TreeItemId of the item to be zapped. Calling this function causes a tree event to be triggered with the event type evt_tree_delete_item.

What styles control the display 465

of the tree control?

Later in this chapter we'll discuss the details of this event type. To leave the item itself, but delete all of its child nodes, call the method DeleteChildren(item) where the item is again a wx.TreeItemId. This method causes all children of the given item to be deleted. Oddly, it does not generate a delete event. To clear the tree entirely, use the method DeleteAllItems(). As you might guess, this method deletes all the items in the tree. It is supposed to generate a separate delete event for each item, however, this does not work on some older MS Windows systems.

Once you've added an item to the tree, you can recover its display text using the method GetItemText(item), where the item is a wx.TreeItemId, and the return value is the display text. If you want to change the text of an item, use the method SetItemText(item, text), where item is again a wx.TreeItemId, and text is the new display text.

Finally, you can get the total number of items in the tree by using the method GetCount(). If you want the number of children under just one specific item, use GetChildrenCount(item, recursively=True). The item parameter is the wx.TreeItemId of the parent. If recursively is False then the method returns only the number of immediate children of the parent, if it is True, the count is for all children no matter what their nested depth.

Was this article helpful?

0 0

Post a comment