Solved

Tree Item Selection States

Posted on 1997-02-18
1
348 Views
Last Modified: 2013-11-20
I have a tree control in one of my document views and I need to be able to enable/disable selection of items in the tree.  This means that when an item is selected and dragged to my other view, I want to still show it in the tree, but disable it from being selected and dragged again.  Any suggestions??
0
Comment
Question by:keithdd
1 Comment
 

Accepted Solution

by:
rob_garner earned 100 total points
ID: 1300055
In the documentation there is a state described - TVIS_DISABLED. Unfortunately this state does not really exist.

So try this...

First, after processing the initial drag set the item so that you know it has been dragged.
You could either do something like...

a.      SetItemState(hItem, TVIS_CUT, TVIS_CUT);
      This will give a visual cue that the item is not available.

      - or -

b.      Set some flag in LPARAM that you can later query
(next steps assume use of TVIS_CUT)

Next, process the TVN_BEGINDRAG notification something like this...

      UINT nFlags = GetItemState(hItem, TVIS_CUT);
      if ( nFlags & TVIS_CUT )
      {
            *pResult = 1;
            AfxMessageBox("Can't drag");
            return;
      }

This will prevent the item from being dragged, but will still allow the item to be selected.

To prevent the selection process the TVN_SELCHANGING notification something like this

void CDiskTreeCtrl::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
{
      NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

      HTREEITEM hItem = pNMTreeView->itemNew.hItem;
      UINT nFlags = GetItemState(hItem, TVIS_CUT);
      if ( nFlags & TVIS_CUT )
      {
            *pResult = 1;
            return;
      }
      
      *pResult = 0;
}


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now