TreeListCtrl In CView With Tool Tips

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 Kb
Download source - 69 Kb


Comments

  • Change the text color of a subitem

    Posted by catia_wapf on 08/03/2006 08:38am

    How 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

    Reply
  • GDI leak ?

    Posted by disc001us on 01/12/2005 10:48am

    Hi, 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

    Reply
  • Solution BUG editable combo/edit

    Posted by Legacy on 09/19/2003 12:00am

    Originally 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())
    {
    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);
    }
    }
    }

    Reply
  • Problem on editable control

    Posted by Legacy on 09/15/2003 12:00am

    Originally 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!

    Reply
  • Bug solution when you double click outside the tree

    Posted by Legacy on 05/16/2003 12:00am

    Originally posted by: Bogdan BRINZAREA

     I found out a small bug in the function that handles the 
    
    double click action. If the double click is outside the
    tree area, below the tree the program generates an error.
    This is because the program tries to handle the message
    for a tree item that doesn't exist.
    The solution is:
    void CTreeListCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
    {

    if((GetColumnsNum()==0) || (point.x<GetColumnWidth(0)))
    {
    CTreeCtrl::OnLButtonDblClk(nFlags, point);
    ResetVertScrollBar();
    }

    SetFocus();

    m_selectedItem = HitTest(point, &nFlags);
    //verify that there is an item selected
    if(m_selectedItem!=NULL)
    ShowEditComboBoxes(point);
    }

    Reply
  • Give me a Break!

    Posted by Legacy on 05/06/2003 12:00am

    Originally 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?

    Reply
  • treecontrol for WEb Page??

    Posted by Legacy on 05/02/2003 12:00am

    Originally 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

    Reply
  • What about shift one place up and down functionality

    Posted by Legacy on 02/24/2003 12:00am

    Originally 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
    gracias

    Reply
  • HELP!!!

    Posted by Legacy on 01/16/2003 12:00am

    Originally 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

    Reply
  • CAN I CHANGE THE COLOR OF LIST/TREE VIEW CONTROL

    Posted by Legacy on 01/13/2003 12:00am

    Originally posted by: DIPESH

    DEAR MADAM/SIR,
    
    

    I HAVE A QUESTION THAT CAN I CHANGE THE COLOR OF EACH LIST VIEW/TREE VIEW CONTROL.
    IF YES HOW CAN I? PLEASE REPLY ME AS EARLY AS POSSIBLE..........

    thanks
    regards
    dipesh

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds