Information générale
Catégorie:
Produits tierce partie
>I am using the treeview control and it seems to fail when attempting 'drag and drop'.
>
>1. the HitTest(x,y) method should return an object (where x,y are the mouse location),instead it returns .NULL. - what am I doing wrong?
>
>2.Setting the DropHighlight property by any means, always generates an error.
As far as using the hit test, I have found that vfp and the treeview control seem to be using a different coordinate system. Be sure your form is set to pixels and then multiply the parameters you are passing to the HitTest method by 15. The following code in MouseDown() works consistently for me.
LPARAMETERS button, shift, x, y
LOCAL lnXCoord, lnYCoord, loNode
* Multiply coordinates for use in call to HitTest()
* For some reason HitTest() is using a finer coordinate
* set than that which is being passed to this method.
lnXCoord = (x * 15)
lnYCoord = (y * 15)
* Get reference to node under mouse cursor if one is present
loNode = this.HitTest(lnXCoord,lnYCoord)
* If mouse cursor is over a node...
IF TYPE("loNode") = "O" AND NOT ISNULL(loNode)
* Some code here
ENDIF
If you are calling the hittest() from a non-ole method, I believe you also have to adjust your X and Y values by multiples of the distence your control's top left corner is from the top left corner of your form. See HitTest in code below for an example of this.
I could not get DropHighlight to work either. I believe I read somewhere that it does not work in VFP. I made do by setting the treeview's HideSelection property in the DragOver event code:
LPARAMETERS oSource, nXCoord, nYCoord, nState
LOCAL lnX, lnY, loHitNode
DO CASE
CASE nState = 0 && entering object
* Set HideSelection property to .F. so that
* selected node shows when we drag over it
this.HideSelection = .F.
* Unselect any previously selected node
IF TYPE("this.SelectedItem") = "O";
AND NOT ISNULL(this.SelectedItem)
this.SelectedItem.Selected = .F.
ENDIF
CASE nState = 1 && leaving object
this.HideSelection = .T.
IF TYPE("this.SelectedItem") = "O";
AND NOT ISNULL(this.SelectedItem)
this.SelectedItem.Selected = .F.
ENDIF
CASE nState = 2 && moving over
* Adjust coordinates for use by hit test
lnX = (nXCoord * 15)-2435
lnY = (nYCoord * 15)-375
* Get reference to node under mouse
loHitNode = This.HitTest(lnX,lnY)
IF Type("loHitNode")="O" AND !ISNULL(loHitNode)
loHitNode.selected = .T.
oSource.DragIcon = "dragmove.cur"
ELSE
oSource.DragIcon = "NoDrop01.cur"
IF TYPE("this.SelectedItem") = "O";
AND NOT ISNULL(this.SelectedItem)
this.SelectedItem.Selected = .F.
ENDIF
ENDIF
ENDCASE
Hope this helps.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement