KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Drag and Drop between controls

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon May 31, 2010 3:37 pm    Post subject: Drag and Drop between controls Reply with quote

I'm still using Kixforms religiously in many scripts used in a myriad of ways. I've run into a situation where I can't get it to quite do what I want. Does anyone know of or can figure out a solution that has thus far eluded me?

I'm trying to enable drag and drop functionality between a ListView and a TreeView. It almost works at this point, but I cannot make the script know which TreeNode the item was "dropped" onto. I'm guessing I'm out of luck since there doesn't appear to be any events supported by the TreeNode object itself. Right now you have to select the TreeNode object first, and then anything from the ListView dragged to the TreeView object will be interpreted to be "dropped" onto the TreeNode that was selected previously.

Code:

Break On

$System = CreateObject("Kixtart.System")

$frmMain         = $System.Form()
$frmMain.Width         = 400
$ = $frmMain.Center()
$stsBar            = $frmMain.StatusBar()
$trvOUs            = $frmMain.TreeView()
$trvOUs.Width         = 100
$trvOUs.Dock         = "Left"
$trvOUs.OnMouseUp      = "trvOUs_MouseUp()"
$trvOUs.OnMouseMove      = "trvOUs_MouseMove()"
$lsvComputers         = $frmMain.ListView()
$lsvComputers.Dock      = "Fill"
$lsvComputers.GridLines      = 1
$lsvComputers.OnMouseDown   = "lsvComputers_MouseDown()"
$lsvComputers.OnMouseMove   = "lsvComputers_MouseMove('lsvComputers')"
$lsvComputers.OnMouseUp      = "lsvComputers_MouseUp()"
$lsvComputers.OnClick      = "lsvComputers_MouseUp()"

Initialize()

$ = $frmMain.Show()
While $frmMain.Visible()
   $ = Execute($frmMain.DoEvents)
Loop
Exit 1

Function Initialize()
   $ = $trvOUs.Nodes.Add("OU1")
   $ = $trvOUs.Nodes.Add("OU2")
   $ = $trvOUs.Nodes.Add("OU3")
   $ = $lsvComputers.Columns.Add("Name",80)
   $ = $lsvComputers.Columns.Add("Type",80)
   $ = $lsvComputers.Items.Add("Computer1")
   $ = $lsvComputers.Items.Add("Computer2")
   $ = $lsvComputers.Items.Add("Computer3")
EndFunction

Function lsvComputers_MouseMove($Source)
   If VarType($btnDrag) = 9
      If $frmMain.MouseX = $btnDragX And $frmMain.MouseY = $btnDragY
         $btnDrag.Visible = 0
      Else
         $btnDrag.Visible = 1
         $btnDrag.Location = $frmMain.MouseX - 40,$frmMain.MouseY + 1
      EndIf
   EndIf
EndFunction

Function lsvComputers_MouseDown()
   $btnDrag      = $frmMain.Button($lsvComputers.FocusedItem.Text)
   $btnDrag.Size      = 80,15
   $btnDrag.Visible   = 0
   $btnDrag.Location   = $frmMain.MouseX - 40,$frmMain.MouseY + 1
   $btnDrag.FlatStyle   = 0
   ;This is required to prevent the button from showing on initial click
   $btnDragX = $frmMain.MouseX
   $btnDragY = $frmMain.MouseY
   $btnDrag.OnMouseEnter   = "lsvComputers_MouseMove('btnDrag')"
   $ = $btnDrag.BringToFront()
   $lsvMouseDown = 1
EndFunction

Function lsvComputers_MouseUp()
   $lsvMouseDown = 0
   $btnDrag = "Nothing"
EndFunction

Function trvOUs_MouseUp()
   If $lsvMouseDown = 1
      $btnDrag = "Nothing"
      $ = MessageBox("Moving " + $lsvComputers.FocusedItem.Text + " to " + $trvOUs.EventNode.Text,"Operation")
   EndIf
   $lsvMouseDown = 0
EndFunction

Function trvOUs_MouseMove()
   If VarType($btnDrag) = 9
      $btnDrag.Location = $frmMain.MouseX - 40,$frmMain.MouseY + 1
   EndIf
EndFunction

_________________
-Ben
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Fri Jun 04, 2010 2:43 am    Post subject: Reply with quote

Change trvOUs_MouseUP to

Code:
Function trvOUs_MouseUp()
   If $lsvMouseDown = 1
      $btnDrag = "Nothing"
      $node = $trvOUs.GetNodeAt($trvOUs.MouseX, $trvOUs.MouseY)
      If VarType($node)
         $ = MessageBox("Moving " + $lsvComputers.FocusedItem.Text + " to " + $node.Text, "Operation")
      EndIf
   EndIf
   $lsvMouseDown = 0
EndFunction
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Thu Jul 22, 2010 4:45 pm    Post subject: Reply with quote

I didn't receive an email that I got a reply, so I am just now coming across it. And very nicely done!!!!

Thanks so much.

_________________
-Ben
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon Jul 26, 2010 11:32 pm    Post subject: Reply with quote

No worries Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group