Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TreeView drag-drop of node only returns the node text
Message
From
27/06/2006 09:28:06
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01131927
Message ID:
01131967
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
>Hi
>
>I have a treeview from which I am dragging a node onto my custom calender class. I only get the data as text of the node. I would like to find the source record in the underlying table that was used to create the TV nodes. The text of the node is not guranteed to be unique thus I would like to connect using a PK which I would use as the key of the node. But as the drag-drop is only providing node text I am a bit confused.
>
>Please advise.

Hope this helps:
Public oForm
oForm = Createobject('myForm')
oForm.Show

Define Class myForm As Form
  Height = 300
  Width = 620
  DoCreate=.T.
  DataSession=2

  Add Object myTree As myTree With ;
    Top = 0, ;
    Left = 0, ;
    Height = 300, ;
    Width = 200

  Add Object myGrid As myGrid With ;
    Top = 0, ;
    Left = 220, ;
    Height = 300, ;
    Width = 400, ;
    Name = "myGrid"

  Procedure Load
    Create Cursor myTest (myID i, myType c(50))
    For ix = 1 To 20
      Insert Into myTest (myID) Values (ix)
    Endfor
    Locate
  Endproc
  Procedure Init
    #Define tvwFirst	0
    #Define tvwLast	1
    #Define tvwNext	2
    #Define tvwPrevious	3
    #Define tvwChild	4

    With This.myTree
      .linestyle =1
      .labeledit =1
      .indentation = 5
      .PathSeparator = '\'
      .Scroll = .T.
      .OLEDragMode = 1
      For ix=1 To 3
        .Nodes.Add(,tvwFirst,"root"+Ltrim(Str(ix)),;
          'Main node '+Ltrim(Str(ix)))
        For jx=1 To 4
          .Nodes.Add("root"+Ltrim(Str(ix)),tvwChild,;
            "child"+Ltrim(Str((ix-1)*4+jx)),;
            'Child '+Ltrim(Str(jx))+' of '+Ltrim(Str(ix)))
        Endfor
      Endfor
    Endwith
  Endproc
Enddefine

Define Class myGrid As Grid
  OLEDropMode = 1
  Procedure OLEDragOver
    Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState
    With This
      lnActiveRow = Ceiling( ;
        ( nYCoord - (.Top + .HeaderHeight) ) / .RowHeight )
      .ActivateCell(lnActiveRow,2)
    Endwith
  Endproc
  Procedure OLEDragDrop
    Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
    If oDataObject.GetFormat(1)
      lcKey = oDataObject.GetData(1)
      With This
        .Columns(2).Text1.Value = m.lcKey+'-'+;
          This.Parent.myTree.Nodes(m.lcKey).Fullpath
      Endwith
    Endif
  Endproc
Enddefine

Define Class myTree As OleControl
  OleClass = 'MSComCtlLib.TreeCtrl'
  nXTwips = 0
  nyTwips = 0

  Procedure Init
    #Define cnLOG_PIXELS_X 88
    #Define cnLOG_PIXELS_Y 90
    #Define cnTWIPS_PER_INCH 1440
    *-- Code for PixelToTwips method
    Local liHWnd, liHDC, liPixelsPerInchX, liPixelsPerInchY

    * Declare some Windows API functions.
    Declare Integer GetActiveWindow In WIN32API
    Declare Integer GetDC In WIN32API Integer iHDC
    Declare Integer GetDeviceCaps In WIN32API Integer iHDC, Integer iIndex

    * Get a device context for VFP.
    liHWnd = GetActiveWindow()
    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.
    This.nXTwips = ( cnTWIPS_PER_INCH / liPixelsPerInchX )
    This.nyTwips = ( cnTWIPS_PER_INCH / liPixelsPerInchY )
  Endproc

  Procedure MouseDown
    *** ActiveX Control Event ***
    Lparameters Button, Shift, x, Y
    With This
      oHitTest = .HitTest( m.x * .nXTwips, m.Y * .nyTwips )
      If Type("oHitTest")= "O" And !Isnull(oHitTest)
        .SelectedItem = oHitTest
      Endif
    Endwith
    oHitTest = .Null.
  Endproc

  Procedure OLEStartDrag
    Lparameters oDataObject, nEffect
    oDataObject.SetData(This.SelectedItem.Key,1)
  Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform