CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2017
    Posts
    4

    MFC tree control highlight item selected by the keyboard ?

    I have this old code in which I had:
    Code:
    void ModCTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
    {
    	UINT uFlags;
    	HTREEITEM htItem = this->HitTest(point, &uFlags);
    	if ((htItem != NULL) && (uFlags & TVHT_ONITEM)) this->Select(htItem, TVGN_DROPHILITE);
    	CTreeCtrl::OnLButtonDown(nFlags, point);
    }
    in a derived class from a CTreeCtrl , actually I don't remember why I needed this (I think it had something to do with selection that changed in the current version , any idea ?) , anyway for some reason this prevent the "blue" highlight of the selected item from happening when I change the selected item using arrow keys , any idea why does this happen and how to fix it ?
    Whenever I change the selected item using arrow key it doesn't get automatically highlighted

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MFC tree control highlight item selected by the keyboard ?

    See CTreeCtrl::Select documentation in MSDN.
    • TVGN_CARET Sets the selection to the given item.
    • TVGN_DROPHILITE Redraws the given item in the style used to indicate the target of a drag-and-drop operation.
    • TVGN_FIRSTVISIBLE Scrolls the tree view vertically so that the given item is the first visible item.
    So, to set the selection to the given item, use TVGN_CARET flag or get rid of that code and let the tree control with its default behavior.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured