Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditionally prevent drag and drop in treeview
Message
De
10/08/2004 08:01:39
 
 
À
09/08/2004 12:14:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00931736
Message ID:
00931998
Vues:
25
Thanks Doug. That worked.

Jason

>Hi Jason.
>
>>Hello all, I need to conditionally control whether a node in a treeview can be dragged and dropped. The user will be able to click on a node to select it, but if the appropriate condition is true then they will not be able to drag and drop the node.
>
>In the MouseDown event, check if the node under the mouse pointer can be dragged, and if not, set the OLEDragMode property to 0 (manual).
>
>Here's some code adapted from my August 2004 article in FoxTalk. This code calls a custom CanStartDrag method to determine if the selected node can be dragged.
>
>
lparameters tnButton, ;
>  tnShift, ;
>  tnXCoord, ;
>  tnYCoord
>#DEFINE BUTTON_LEFT     1
>#DEFINE DRAG_MANUAL           0      && 0 - Manual
>#DEFINE DRAG_AUTOMATIC        1      && 1 - Automatic
>local loNode
>with This
>
>* Ensure the node under the mouse is selected.
>
>  loNode = .HitTest(tnXCoord * Thisform.nTreeFactorX, ;
>    tnYCoord * Thisform.nTreeFactorY)
>  if not isnull(loNode)
>    .NodeClick(loNode)
>  endif not isnull(loNode)
>
>* If this is the left mouse button, determine whether we can drag from the
>* selected node or not.
>
>  if tnButton = BUTTON_LEFT
>    .OLEDragMode = iif(.CanStartDrag(), DRAG_AUTOMATIC, DRAG_MANUAL)
>  endif tnButton = BUTTON_LEFT
>endwith
>
>The nTreeFactorX and nTreeFactorY properties used in this code are set in the following code (called from Init):
>
>
* Calculate the conversion factor between VFP window units (in pixels) and
>* TreeView window units (in twips).
>
>#define cnLOG_PIXELS_X		  88
>#define cnLOG_PIXELS_Y		  90
>#define cnTWIPS_PER_INCH	1440
>local liHWnd, ;
>  liHDC, ;
>  liPixelsPerInchX, ;
>  liPixelsPerInchY
>
>* Declare some Windows API functions.
>
>declare integer GetDC         in Win32API ;
>  integer iHDC
>declare integer GetDeviceCaps in Win32API ;
>  integer iHDC, integer iIndex
>declare integer ReleaseDC     in Win32API ;
>  integer ihWnd, integer iHDC
>
>* Get a device context for VFP.
>
>liHWnd = _vfp.hWnd
>liHDC  = GetDC(liHWnd)
>
>* Get the pixels per inch.
>
>liPixelsPerInchX = GetDeviceCaps(liHDC, cnLOG_PIXELS_X)
>liPixelsPerInchY = GetDeviceCaps(liHDC, cnLOG_PIXELS_Y)
>
>* Get the twips per pixel.
>
>with This
>  .nTreeFactorX = cnTWIPS_PER_INCH/liPixelsPerInchX
>  .nTreeFactorY = cnTWIPS_PER_INCH/liPixelsPerInchY
>endwith
>
>* Clean up.
>
>ReleaseDC(liHWnd, liHDC)
>clear dlls GetDC, GetDeviceCaps, ReleaseDC
>
>Doug
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform