TreeListCtrl In CView With Tool Tips
Posted
by Gary Andrew Lewis
on January 13th, 2003
Environment: VC6, MFC
This project was written to provide you with a Tree List to put on any CView. It supports images, checkboxes, and all the functionality of both CTree and CList Controls. It automatically resizes itself when the user changes the window that has been attached to it. Clicking on the List Header will sort the tree either in ascending or descensding order. Each cell is also editable and can have either an edit box or a combo box for this purpose.
Just have a look at the accompanying code; if you have any problems, don't hesitate to e-mail me. All source code is provided in zips below. Just download and enjoy!
Downloads
Download demo project - 24 KbDownload source - 69 Kb

Comments
Change the text color of a subitem
Posted by catia_wapf on 08/03/2006 08:38amHow can I change the textcolor of a specific subitem of a tree item? I have a tree list with 5 columns and one of them is called "Priority". Each priority item in this column should have a specific text color. How can I do that? How can I change the text color of a subitem? Thanks a lot. Regards Catia
ReplyGDI leak ?
Posted by disc001us on 01/12/2005 10:48amHi, great control!! very useful. but when I try the demo, passing with the mouse on the grid, I see GDI objects growing in task manager ( windows XP SP2 ) davide
ReplySolution BUG editable combo/edit
Posted by Legacy on 09/19/2003 12:00amOriginally posted by: gabave
When i edit combo/ edit box after move the scroll bar values isn't right. This code is a solution to this bug.
void CTreeListCtrl::ShowEditComboBoxes(POINT point)
{
CDependDlg *pFrame = (CDependDlg*)GetParent();
int nMin, nMax, nPos;
if (pEdit)
{
delete pEdit;
}
if (pCombo)
{
delete pCombo;
}
//gets text of current column and row
CTLItem *pItem = (CTLItem *)CTreeCtrl::GetItemData(m_selectedItem);
if ((m_selectedItem)&&((pItem->IsEditable())||(pItem->HasCombo())))
{
DWORD dwStyle;
CTLItem *pItem=NULL;
CString csSelectedSubText="";
int nLastLeftPos=0;
POINT tempPoint=point;
tempPoint.y=3;
int nCol = m_wndHeader.GetItemCount();
pFrame->m_horScrollBar.GetScrollRange(&nMin, &nMax);
nPos = pFrame->m_horScrollBar.GetScrollPos();
CRect tree;
GetClientRect(&tree);
tempPoint.x += nPos;
for (int i=0;i<nCol;i++)
{
CRect rect(nLastLeftPos,2,GetColumnWidth(i)+nLastLeftPos,4);
if (PtInRect(rect, tempPoint))
{
pItem = (CTLItem *)CTreeCtrl::GetItemData(m_selectedItem);
// get current string in column
csSelectedSubText=pItem->GetSubstring(i);
// work out edit box size
CRect m_labelRect;
GetItemRect( m_selectedItem, &m_labelRect,TRUE );
rect.top=m_labelRect.top;
rect.bottom=rect.top+m_labelRect.Height();
// if first column then restrict label left offset and left align text
if (i==0)
{
dwStyle=ES_LEFT;
rect.right -= nPos;
if( !nPos )
rect.left=m_labelRect.left;
else
{
rect.left = 0;
rect.right = GetColumnWidth(i);
}
}
else
{
dwStyle=ES_RIGHT;
int colWidth = GetColumnWidth(i);
int colRight = abs(rect.right -= nPos);
int colLeft = abs(tree.right - nLastLeftPos + nPos);
if( colLeft < colWidth )
{
rect.right = tree.right;
rect.left = tree.right - colWidth;
}
else if( colRight < colWidth )
{
rect.left = 0;
rect.right = colWidth;
}
else
{
rect.left= nLastLeftPos - nPos;
rect.right = colRight;
}
}
if (pItem->IsEditable())
Reply{
dwStyle|=WS_BORDER |WS_CHILD| WS_VISIBLE| ES_AUTOHSCROLL;
// create edit box
pEdit = new CTreeListEditBox(m_selectedItem, i, csSelectedSubText);
pEdit->Create(dwStyle, rect, this, 1);
}
else
{
dwStyle |= WS_CHILD |WS_TABSTOP| WS_VISIBLE| WS_VSCROLL| CBS_DROPDOWNLIST;
rect.top-=2
rect.bottom=rect.top+100;
pCombo = new CTreeListComboBox(m_selectedItem, i, csSelectedSubText);
pCombo->Create(dwStyle, rect, this, 1);
}
}
nLastLeftPos=nLastLeftPos+GetColumnWidth(i);
}
}
}
Problem on editable control
Posted by Legacy on 09/15/2003 12:00amOriginally posted by: gave
When i do double click on item of the list/tree control after shifted the horizontal scroll bar the label of the item isn't right. Function GetColumnsNum() in ShowEditComboBoxes() return a wrong value!
ReplyBug solution when you double click outside the tree
Posted by Legacy on 05/16/2003 12:00amOriginally posted by: Bogdan BRINZAREA
Reply
Give me a Break!
Posted by Legacy on 05/06/2003 12:00amOriginally posted by: Cary Martin
Could you all please give these contributors a break!
They atleast took the time and effort to contribute.
the least you can do is take what they offer, and use it
it you can, if you can't just move on.
What do you have to contribute?
Replytreecontrol for WEb Page??
Posted by Legacy on 05/02/2003 12:00amOriginally posted by: Purushoth
i would like to access data from database into each nodes of tree.would it be faster while rendering into browser, as thousands of nodes to be displayed to client??, would it be faster upon collapse or expand of tree for large nodes.
- Purushoth
ReplyWhat about shift one place up and down functionality
Posted by Legacy on 02/24/2003 12:00amOriginally posted by: gracias carol
hi
it looks to me that u have done good work in tree control , i am looking for adding the right click menu pop up option of shift up and shift down on the selected node of tree control. Need help on it right now my cut/copy/paste/drag/drop are working fine.
Thanks
Replygracias
HELP!!!
Posted by Legacy on 01/16/2003 12:00amOriginally posted by: Ajay pandey
Hi,
I Need to create a full working tree outlook style using activx tree object. can anybody guide me how to do it?
thanx
ReplyCAN I CHANGE THE COLOR OF LIST/TREE VIEW CONTROL
Posted by Legacy on 01/13/2003 12:00amOriginally posted by: DIPESH
ReplyLoading, Please Wait ...