CTreeView Class |
Description
A tree-view control is a window that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and directories on a disk. Each item consists of a label and an optional bitmapped image, and each item can have a list of subitems associated with it. By clicking an item, the user can expand or collapse the associated list of subitems.
CTreeView is the class which creates a tree-view control. It can be used as a control in a Dialog, or as the View window in a Frame, Docker, MDI child.
Refer to the documentation that ships with the Microsoft Windows Software Development Kit for more information on the use of tree view controls.
CTreeView Members
Constructor
CTreeView | CTreeView();Constructs a CTreeView. |
Attributes
GetBkColor | COLORREF GetBkColor() const;Retrieves the current background color of the control. |
GetChild | HTREEITEM GetChild(HTREEITEM hItem) const;Retrieves the first child item of the specified tree-view item. |
GetCount | UINT GetCount() const;Retrieves a count of the items in a tree-view control. |
GetDropHiLightItem | HTREEITEM GetDropHiLightItem() const;Retrieves the tree-view item that is the target of a drag-and-drop operation. |
GetEditControl | CEdit* GetEditControl() const;Retrieves the handle to the edit control being used to edit a tree-view item's text. |
GetFirstVisible | HTREEITEM GetFirstVisible() const;Retrieves the first visible item in a tree-view control window. |
GetImageList | CImageList* GetImageList(int iImageType) const;Retrieves the normal or state image list associated with a tree-view control. |
GetIndent | UINT GetIndent() const;Retrieves the amount, in pixels, that child items are indented relative to their parent items. |
GetInsertMarkColor | COLORREF GetInsertMarkColor() const;Retrieves the color used to draw the insertion mark for the tree-view. |
GetItem | BOOL GetItem(TVITEM& Item) const;Retrieves some or all of a tree-view item's attributes. |
GetItemData | DWORD_PTR GetItemData(HTREEITEM hItem) const;Retrieves the application data from a tree-view item. |
GetItemHeight | int GetItemHeight() const;Retrieves the current height of the tree-view items. |
GetItemImage | BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const;Retrieves the index of the normal image and the selected image. |
GetItemRect | BOOL GetItemRect(HTREEITEM hItem, CRect& rc, BOOL bTextOnly) const;Retrieves the bounding rectangle for a tree-view item and indicates whether the item is visible. |
GetItemText | CString GetItemText(HTREEITEM hItem, UINT nTextMax /* = 260 */) const;Retrieves the text from a tree-view item. |
GetLastVisible | HTREEITEM GetLastVisible() const;Retrieves the last expanded item in a tree-view control. This does not retrieve the last item visible in the tree-view window. |
GetNextItem | HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const;Retrieves the tree-view item that bears the specified relationship to a specified item. |
GetNextSibling | HTREEITEM GetNextSibling(HTREEITEM hItem) const;Retrieves the next sibling item of a specified item in a tree-view control. |
GetNextVisible | HTREEITEM GetNextVisible(HTREEITEM hItem) const;Retrieves the next visible item that follows a specified item in a tree-view control. |
GetParentItem | HTREEITEM GetParentItem(HTREEITEM hItem) const;Retrieves the parent item of the specified tree-view item. |
GetPrevSibling | HTREEITEM GetPrevSibling(HTREEITEM hItem) const;Retrieves the previous sibling item of a specified item in a tree-view control. |
GetPrevVisible | HTREEITEM GetPrevVisible(HTREEITEM hItem) const;Retrieves the first visible item that precedes a specified item in a tree-view control. |
GetRootItem | HTREEITEM GetRootItem() const;Retrieves the topmost or very first item of the tree-view control. |
GetScrollTime | int GetScrollTime() const;Retrieves the maximum scroll time for the tree-view control. |
GetSelection | HTREEITEM GetSelection() const;Retrieves the currently selected item in a tree-view control. |
GetTextColor | COLORREF GetTextColor() const;Retrieves the current text color of the control. |
GetToolTips | CToolTip* GetToolTips() const;Retrieves the handle to the child ToolTip control used by a tree-view control. |
GetVisibleCount | UINT GetVisibleCount() const;Obtains the number of items that can be fully visible in the client window of a tree-view control. |
ItemHasChildren | BOOL ItemHasChildren(HTREEITEM hItem) const;Returns TRUE if the item has children. |
SetBkColor | COLORREF SetBkColor(COLORREF clrBk) const;Sets the background color of the control. |
SetImageList | BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage) const;Sets the normal or state image list for a tree-view control and redraws the control using the new images. |
SetIndent | void SetIndent(int indent) const;Sets the width of indentation for a tree-view control and redraws the control to reflect the new width. |
SetInsertMark | BOOL SetInsertMark(HTREEITEM hItem, BOOL fAfter = TRUE) const;Sets the insertion mark in a tree-view control. |
SetInsertMarkColor | COLORREF SetInsertMarkColor(COLORREF clrInsertMark) const;Sets the color used to draw the insertion mark for the tree view. |
SetItem | BOOL SetItem(TVITEM& Item) const; BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR szText, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam) const;Sets some or all of a tree-view item's attributes. |
SetItemData | BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData) const;Sets the application data for a tree-view item. |
SetItemHeight | int SetItemHeight(SHORT cyItem) const;Sets the height of the tree-view items. |
SetItemImage | BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage) const;Sets the index of the normal image and the selected image. |
SetItemText | BOOL SetItemText(HTREEITEM hItem, LPCTSTR szText) const;Sets the text of a tree-view item. |
SetScrollTime | UINT SetScrollTime(UINT uScrollTime) const;Sets the maximum scroll time for the tree-view control. |
SetTextColor | COLORREF SetTextColor(COLORREF clrText) const;Sets the text color of the control. |
SetToolTips | CToolTip* SetToolTips(CToolTip* pToolTip) const;Sets a tree-view control's child ToolTip control. |
Operations
CreateDragImage | CImageList* CreateDragImage(HTREEITEM hItem) const;Creates a dragging bitmap for the specified item in a tree-view control. An application can display the image when dragging the item by using the image list functions. |
DeleteAllItems | BOOL DeleteAllItems() const;Deletes all items from a tree-view control. |
DeleteItem | BOOL DeleteItem(HTREEITEM hItem) const;Removes an item and all its children from a tree-view control. |
EditLabel | HWND EditLabel(HTREEITEM hItem) const;Begins in-place editing of the specified item's text, replacing the text of the item with a single-line edit control containing the text. This function implicitly selects and focuses the specified item. |
EndEditLabelNow | BOOL EndEditLabelNow(BOOL fCancel) const;Ends the editing of a tree-view item's label. |
EnsureVisible | BOOL EnsureVisible(HTREEITEM hItem) const;Ensures that a tree-view item is visible, expanding the parent item or scrolling the tree-view control, if necessary. |
Expand | BOOL Expand(HTREEITEM hItem, UINT nCode) const;The TreeView_Expand macro expands or collapses the list of child items associated with the specified parent item, if any. |
HitTest | HTREEITEM HitTest(TVHITTESTINFO& ht) const;Determines the location of the specified point relative to the client area of a tree-view control. |
InsertItem | HTREEITEM InsertItem(TVINSERTSTRUCT& tvIS) const;Inserts a new item in a tree-view control. |
Select | BOOL Select(HTREEITEM hitem, UINT flag) const;Selects the specified tree-view item, scrolls the item into view, or redraws the item in the style used to indicate the target of a drag-and-drop operation. |
SelectDropTarget | BOOL SelectDropTarget(HTREEITEM hItem) const;Redraws a specified tree-view control item in the style used to indicate the target of a drag-and-drop operation. |
SelectItem | BOOL SelectItem(HTREEITEM hItem) const;Selects the specified tree-view item. |
SelectSetFirstVisible | BOOL SelectSetFirstVisible(HTREEITEM hItem) const;Scrolls the tree-view control vertically to ensure that the specified item is visible. If possible, the specified item becomes the first visible item at the top of the control's window. |
SortChildren | BOOL SortChildren(HTREEITEM hItem, BOOL fRecurse) const;Sorts the child items of the specified parent item in a tree-view control. |
SortChildrenCB | BOOL SortChildrenCB(TVSORTCB& sort, BOOL fRecurse) const;Sorts tree-view items using an application-defined callback function that compares the items. |
Overridables
PreRegisterClass | virtual void PreRegisterClass(WNDCLASS &wc);Set the window class parameters before the window is created. |
Base class Members
For base class members, refer to the members of CWnd.
Remarks
Like all common controls, the Tree-VIew control requires a parent window. This parent window is often a dialog, but simple windows can also be the parent window for a Tree-View control.
Refer to the explorer sample to see a demonstration of the CListView and CTreeView classes.
Summary Information
Header file | treeview.h |
Win32/64 support | Yes |
WinCE support | Yes |
Library required | Comctl32.lib |