Click here to Skip to main content
Click here to Skip to main content

A Tree List Control

By , 19 Sep 2002
 
<!-- Add the rest of your HTML here -->

Introduction

This is a class derived from CWnd class. It's a tree control with a list.

Features

Below are some of the many features that CTreeListCtrl has:

  • Compatible with CTreeCtrl & CListCtrl
  • Header drag & drop
  • Drag & drop between CTreeListCtrl
  • Transparent drag window with Alpha blend
  • Double colors of list
  • Background image
  • Check box support
  • Lock box support
  • Embedded modified controls
  • No more in future

Snapshot 1

Snapshot 2


How to use it

Add this string into stdafx.h
#include "..\\TurboDLL\\xTurboDll.h"

Define your controls

class CMyTreeListCtrl : public CTreeListCtrl  
{
public:
  CMyTreeListCtrl();
  virtual ~CMyTreeListCtrl();

protected:
  //{{AFX_MSG(CMyTreeListCtrl)
  afx_msg void OnExpanding(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnExpanded(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnUpdating(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnUpdated(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragEnter(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragLeave(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragOver(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDrop(NMHDR* pNMHDR, LRESULT* pResult);
  //}}AFX_MSG

  DECLARE_MESSAGE_MAP()
};

Use your controls

class CTurboDragDlg : public CDialog
{
// Construction
public:
  CTurboDragDlg(CWnd* pParent = NULL);   // standard constructor
        ...
  CImageList  m_ImageList;
  CMyTreeListCtrl  m_tree1;
  CMyTreeListCtrl m_tree2;
        ...
};

CTurboDragDlg::OnInitDialog() 
{
  CDialog::OnInitDialog();
  
  // TODO: Add extra initialization here
  m_ImageList.Create( IDB_BITMAP_TREE, 16, 4, 0xFF00FF );

  CRect rect;
  GetClientRect(&rect);
  rect.DeflateRect( 5, 5, 5, 5 );

  CRect left;
  left = rect;
  left.right = ( rect.left + rect.right ) / 2;

  CRect right;
  right = rect;
  right.left = ( rect.left + rect.right ) / 2;

  m_tree1.Create( 0x50810000, left, this, 0 );
  m_tree2.Create( 0x50810000, right, this, 1 );

        // Add other initialize code here
        ...
        
        return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}

Then use it freely.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

TigerX
Web Developer
China China
He is a Visual C++ developer, MCSE
He has been programming in C/C++ for 7 years, Visual C++ with MFC for 5 years and RDBMS: Oracle, MS SQL for 5 years

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to convert the project to "Use MFC in a Static Library"? Pinmemberthelastphoenix24-Oct-11 23:45 
How to convert the project to "Use MFC in a Static Library" step by step?
Any suggestion?Confused | :confused: Confused | :confused:
GeneralMy vote of 5 PinmemberMember 75250315-Sep-11 23:56 
Thank You China!
GeneralUnable to Edit the columns. PinmemberMahadev HK4-May-11 15:41 
I have configured columns as shown below
m_ctrlTreeList.SetColumnModify( 1, TLM_COMBO );
m_ctrlTreeList.SetColumnDefaultText( 1, "600|700|800" );
 
But when i click on the column the combobox wont shown up.
Please advise if any property needs to be configured.
 
Thanks
Mahadev

GeneralRe: Unable to Edit the columns. PinmemberModal sun20-Sep-11 15:30 
GeneralRe: Unable to Edit the columns. Pinmemberthelastphoenix16-Nov-11 15:42 
GeneralTuroboDll behaviour in Windows Vista or Windows 7 PinmemberMember 115045326-Oct-10 22:38 
Hello Dear Developers! Hello TigerX!
 
TurboDLL Controls is a great software component - well used in a lot of my toolssince years.
 
Now we make first experiences with windows 7. We see a strange visual effect during drag & drop operation.
During mouse movement a middle-large GREY and TRANSPARENT rectangle is around the mouse. I found that the layered windows did cause the effect.
 
If I exclude (comment out) in CTLCDragWnd::OnPaintBMP the following code sequence
...
g_lpfnUpdateLayeredWindow (
GetSafeHwnd(), pPDC -> GetSafeHdc(), &rcWindow.TopLeft(), &CSize( rcWindow.Width(), rcWindow.Height() ),
m_dcMem.GetSafeHdc(), &CPoint( 0, 0 ),
0x00, &bf, ULW_ALPHA);
g_lpfnSetLayeredWindowAttributes( GetSafeHwnd(), 0x000000, 160, ULW_ALPHA );
...
the grey rectangle disappear.
 
DID ANYBODY HAVE AN IDEA HOW THE CODE HAVE TO LOOK TO BE "Vista" OR "W 7" compatible?
 
Thank you very mach! Every help is welcome.
 
With kind regards
 
Marko Winter
Questionhow to add combobox items PinmemberSakhalean3-Aug-10 21:34 
I want to add combo box items to the list control
How to add items to combobox
and where to add combo box items.
 
Pls help me.
AnswerRe: how to add combobox items PinmemberMember 115045326-Oct-10 22:54 
GeneralRe: how to add combobox items PinmemberSakhalean27-Oct-10 17:42 
GeneralRe: how to add combobox items Pinmemberdd_dzs10-Apr-11 22:05 
1 m_ctrStat.SetColumnModify(nCol, TLM_COMBO );
2 m_ctrStat.SetColumnDefaultText(nCol, "xx|mm|ss" );
3 m_ctrStat.SetItemText(pItem, "xx", nCol);
QuestionThe tree list control PinmemberYeMeGe20-May-10 11:24 
Confused | :confused:
How can i insert an item in column n(n != 0)?
 
mr_lc
20100521
thanks a lot.
QuestionHow to solve Bug using ComboBox Pinmemberuara8229-Oct-09 16:41 
First of all, thanks for distribution this control.
But i found bug this control using with CComboBox.
I put this control in Dialog Box, and combobox too.
After popup dialog, some data in combox print this control's columns.
How can i solve this problem?
Help me, please~
General"A required resource was unavailable" PinmemberNaryoril1-Sep-09 1:19 
I get this error as soon as I create the second CTreeListCtrl object (not the control, the object itself). It doesn't matter if the first of those objects is destroyed before the second is created or not.
Does anybody have an idea?
Generalfind a bug Pinmember7817537914-May-09 21:24 
when the ParentItem was not Expended
I use GetItemCount(),and GetItemText( int nItem, int nSubItem ), there will be a bug.
GeneralMultiline text inNode Pinmemberjatin dave20-Jan-09 21:48 
Sir, Great application, but i want multiline text in node,
for e.g.
 
first view:
 
+ Node
 

Then:
 
- Node
+ Node is in
Multiline
GeneralCrash in CancelControl() on 64 bit platforms. PinmemberMember 431310519-Dec-08 2:15 
The code seems to crash sometimes in the CTreeListCtrl::CancelControl(). Anyone seen this issue and found a fix for it?
 
-Ashutosh
QuestionCrash in CancelModify - after ESCAPE key PinmemberMember 115045312-Nov-08 23:30 
Hello dear Community!
 
We are using the Tree List Control in TurboDll succesful in some of our programs. In general it is working fine. But in sometimes I get a crash in following function of TurboDLL:
 
BOOL CTreeListCtrl::CancelModify()
{
...
   // cancel all columns of an item
   CancelControl();
   // restore values from m_pUpdateItem
   for( int iColumn = 0; iColumn < GetColumns(); iColumn++ )
   {
THE FOLLWING CODE CAUSES THE CRASH:
      m_pModifyItem->SetText( m_pUpdateItem->GetText( iColumn ), iColumn );
   }
...       
     return TRUE;
}
 
let me explain what happens in program around?
I use ComboBox Control in the the Tree List Ctrl - if combo box is elapsed and an entry is changed and ESCAPE key is pressed. I process the bevovior in OnEndCOntrol. Then the crash comes a SECOND cal of OnEndControl.

Do I made something wrong in .OnEndControl.   if necessary I could post more code. Any hints are welcome. Thanks in advance
 
Confused | :confused:
Greetings from
 
Marko Winter
Software & Systems
SysMik GmbH Dresden
GeneralFind a text and highlight Pinmembermohadeb14-Oct-08 3:22 
Hi,
I am using treelist control and now i require to implement a search and highlight text feature in it.
Though i am able to find a text but unable to highlight it.
For example if i have "Ram is a good boy" in a column in tree list control, and if i search with 'good' then it should highlight good instead of whole column.
 
Can you please help me in this matter?
Thanx in advance
 
Regards,
Deb

Question跪求,老大这个怎么编译Release版本? Pinmembertuhaitao9-Jun-08 19:07 
display No MFC error:
kill this in xTurboDLL.h can access compile
/*
#ifndef _AFXDLL
#pragma message("*** XXXXXXXXXXXXXXXXXXXXXXXXXXXX ***")
#pragma message("*** Must Using MFC in Shared DLL ***")
#pragma message("*** XXXXXXXXXXXXXXXXXXXXXXXXXXXX ***")
#error No MFC
#endif
*/
 
but this TreeList can't display like Debug.Dispaly error!
AnswerRe: 跪求,老大这个怎么编译Release版本? PinmembercnZhangcm26-Mar-09 22:21 
GeneralRe: 跪求,老大这个怎么编译Release版本? Pinmemberspaceknight7-Jul-09 17:43 
GeneralRe: 跪求,老大这个怎么编译Release版本? Pinmembermaicoye22-Jul-09 21:59 
QuestionCrashed when I Expand All the Items in Release Version Pinmembermconstor27-Apr-08 19:36 
Sometimes,when it Crashed, I can see the twinkling stripes.
But It is ok in Debug Version.
And if the TreeList has not a lots of items,It is ok and it will not Crash
Anyone has ever seen this?
Thanks!
 
modified on Monday, April 28, 2008 5:51 AM

AnswerRe: Crashed when I Expand All the Items in Release Version Pinmembermconstor31-May-08 18:26 
Generaltotally useles code for existing control Pinmemberkilt26-Apr-08 5:00 
The Tree-List control is a native Win32 control for ages.
Why reinventing the wheel ?...
GeneralRe: totally useles code for existing control PinmemberKochise1-Oct-08 6:51 
Questionthe Combobox control cannot be dropdown when use together with TreeListCtrl in a same dialogbox [modified] Pinmemberdoublestone8-Apr-08 2:51 
Cry | :(( When a dialogbox has run with this TreeListCtrl, the Combobox of the same dialogbox cannot be dropdown. I have tested for several times.The result always is same. You may try this case in the TurbodllDemo.For example you add a Combobox control on the demo dialogbox and add some data into the list of   combobox.And then you click the arrow of Combobox, You will find the combobox cannot be dropdown by anyway.
Does anyone konw how to resolve this problem?
 
<div class="ForumMod">modified on Monday, April 14, 2008 9:57 AM</div>
QuestionCan we use the code freely? PinmemberMember 461932710-Dec-07 14:12 
Is there any copyright limitation?
QuestionCan you not show expansion boxes on leaf items? PinmemberSteve_Harris14-Nov-07 23:45 
Is it possible to not display [+] boxes on leaf items in the tree? It is confusing to the user, because it looks like you can open the item to show more items, when it is in fact the lowest you can go. It disappears when you click on it, but it would be better not to show it in the first place!
 

AnswerRe: Can you not show expansion boxes on leaf items? Pinmemberahrdmy harmy8-Mar-09 20:52 
QuestionHow to include TurboDLL staticaly into a project [modified] PinmemberKochise9-May-07 21:16 
If you don't want to link your project with TurboDLL.dll but want to create a standalone executable file, here's the steps to follow :
 
1- Include the following Bitmaps in your ressource tree :
 
IDB_TREELIST_BITMAP (res\BM_BKGND.BMP)
IDB_TREELIST_CHECK (res\bm_checkbox.bmp)
IDB_TREELIST_DISABLE (res\bm_bkgnd2.bmp)
IDB_TREELIST_HEADER (res\bm_def_head.bmp)
IDB_TREELIST_LOCK (res\bm_lockbox.bmp)
IDB_TREELIST_SORT (res\bm_def_sort.bmp)
IDB_TREELIST_TREE (res\bm_def_tree.bmp)
 
2- Include the following Cursors in your ressource tree :
 
IDC_CURSOR1 (res\cursor1.cur)
IDC_CURSOR_BUTTON (res\cur_button.cur)
IDC_CURSOR_CHECK (res\cur_checkbox.cur)
IDC_CURSOR_CROSS (res\cur_cross.cur)
IDC_CURSOR_DROP (res\CUR_DROP.CUR)
IDC_CURSOR_HORZ (res\CUR_HORZ.CUR)
IDC_CURSOR_LOCK (res\cur_lockbox.cur)
IDC_CURSOR_SIZE (res\CUR_SIZE.CUR)
IDC_CURSOR_SPLIT (res\cur_split.cur)
IDC_CURSOR_STOP (res\CUR_STOP.CUR)
IDC_CURSOR_VERT (res\CUR_VERT.CUR)
 
3- Add this to "stdafx.cpp"
 
#include "./TreeListResource.h"

CTreeListResource::CTreeListResource()
{
}
 
CTreeListResource::~CTreeListResource()
{
}
 
4- Add these lines to "stdafx.h" to turns the code into a non DLL/exported one :
 
#undef AFX_EXT_CLASS
#define AFX_EXT_CLASS
 
#include "./TurboDLL.h"
 
5- In "TurboDLL.h" uncomment the following line to allow the use of CArray :
 
#include <<Afxtempl.h>>
 
And you're done !
 
Kochise
 
In Code we trust !

AnswerRe: How to include TurboDLL staticaly into a project Pinmembernet_id1-Jan-09 19:58 
Generalin-list editing of subitem PinmemberMike Eriksson12-Apr-07 23:49 
Hello,
 
First I would Like to thank you for this control.
 
I do not understand how to let the user edit a value in a subitem of the list. If someone would explain how to do this I would appreciate it very much!
 
I have tried to add an nLButtonDblClk() to my subclass of the control and then call BeginModify() with the item and col that the user has dubble clicked in. But nothing happens....Confused | :confused:
 

Please Help!
 

 
Mike Eriksson
--

GeneralRe: in-list editing of subitem PinmemberMike Eriksson13-Apr-07 21:53 
GeneralRe: in-list editing of subitem PinmemberMr.SeYeu6-Jul-08 16:11 
QuestionSorting? PinmemberLittleIan3-Apr-07 1:02 
There seems to be some support for sorting but I am not sure enough to make it actually sort items as they are being inserted. Any ideas or clues?
 
Little Ian
QuestionSortChildren PinmemberJordan Walters2-Apr-07 12:24 
Hello TigerX
Thanks for the control. It is great but for one thing. It says it fully supports CListCtrl and yet there is no SortChildren method. Is there another way I can sort child tems of a particular node?
Jordan
 
Ashes to ashes, DOS to DOS.

GeneralCan't include in my .NET 2003 project!! PinmemberKhanafer24-Nov-06 6:20 
Hello,
 
When I include the files in my project, I get about 252 warnings: inconsistent dll linkage Frown | :(
 
Any solutions?
 
Thanks
 
AK
QuestionHow to implementation Print list item? Pinmembertangversion15-Oct-06 20:33 
thanks!
Generali can't add it in asp.net control(VB code) PinmemberPhan Thanh Lam8-Oct-06 17:56 
i can't turbodll.dll in asp.net control. i hope you hepl me!Thanks you very much!Confused | :confused:
 
Lam thank you!I hope you sucessful

GeneralRe: i can't add it in asp.net control(VB code) PinstaffChristian Graus8-Oct-06 19:05 
QuestionSet color in subitems Pinmembercatia_wapf3-Aug-06 2:20 
How can I set color if a specific subitem of a treectrl?
I can only change color of an item, that means a line of a treectrl. I want to change color of a specific subitem of this line.
 
Thanks
 
Regards
 
Catia

AnswerRe: Set color in subitems Pinmembertangversion15-Oct-06 20:29 
GeneralCan´t delete columns... Pinmembervertex_x17-Apr-06 1:44 
Hi there,
 
first: great control!
 
DeleteColumn(iCol) runns into Assertion
ASSERT( m_pRootItem->m_pChild == NULL );
at TreeListCtrl.cpp line 3419
but why?
Can anyone describe how to delete a column without running into this assertion?
What is m_pRootItem->m_pChild?
What is if m_pRootItem->m_pChild == NULL?
Sorry for posting here, but the Documentation is a bit weak ;o)
 
cheeerz,
vertex
 
_
__ _____ _ __| |_ _____ __
\ \ / / _ \ '__| __/ _ \ \/ /
\ V / __/ | | || __/> <
\_/ \___|_| \__\___/_/\_\
QuestionHow to print? Pinmembertangversion27-Mar-06 19:05 

How to print?
 
Thanks!
GeneralLot of Flicker when Resizing PinmemberBagul Buva8-Mar-06 11:58 
First, thanks a lot for such a great work. I really appreciate your efforts.
 
I have some comments:
 
I downloaded the demo project from the .fr site and did some modifications:
- Dialog border to Resizing
- Moved the 'static text status labels' from the bottom to top so that tree-resizing logic/code is simple.
- Added CTurboDemoDlg::OnSize() message, which resizes the tree:
void CTurboDemoDlg::OnSize(UINT nType, int cx, int cy) 
{
    CDialog::OnSize(nType, cx, cy);
    if(!m_ctrlTreeList.GetSafeHwnd())
    {
        return;
    }
    CRect rectClient;
    GetClientRect(&rectClient);
    CRect rectTree;
    m_ctrlTreeList.GetWindowRect(rectTree);
    ScreenToClient(rectTree);
    int iSpacing = 10;
    m_ctrlTreeList.SetWindowPos(
        NULL,
        rectTree.left, 
        rectTree.top,
        rectClient.Width() - 2 * iSpacing,
        rectClient.bottom - rectTree.top,
        SWP_NOZORDER
        );
}
 
- Commented the FeedTree() call from OnInitDialog()
 
Now when you resize the dialog, there is a lot of flicker in the tree. The flicker occurs regardless of whether the tree is empty or filled. I checked the Explorer's tree control (SysTreeView32) and there is a lot of flicker there, too. System's list control (SysListView32), however, doesn't have any flicker even when you resize it.
 
Anyways, is there anyway you can reduce / eliminate the flicker?
 


QuestionFind a bug when moving colums Pinmemberochoteau7-Dec-05 23:59 
When there is few items in the CTreeList and vertical bar is not dispalyed, then moving columns larger to the CTreeList window, lead to the CTreeList window to disappear instead of displaying the horizontal scroll bar !!!
 
If anyone have a solution to correct this bug ...
 
NB : have this bug only if compiled in release mode !
AnswerRe: Find a bug when moving colums Pinmemberhoker.ffb28-Jun-06 20:57 
General@TigerX Pinmemberyokosuna30-Nov-05 19:08 
How about incooperating all suggested enhancements from this messageboard and update the sources ?
Thank you.
 
yoko
GeneralDone it, done that... PinmemberKochise20-Jan-06 4:56 
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 20 Sep 2002
Article Copyright 2002 by TigerX
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid