Solved

Tree Item Selection States

Posted on 1997-02-18
1
352 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

827 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