• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Tree Item Selection States

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
keithdd
Asked:
keithdd
1 Solution
 
rob_garnerCommented:
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now