Solved

Tree Item Selection States

Posted on 1997-02-18
1
343 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

771 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