| View previous topic :: View next topic |
| Author |
Message |
Bonji KiXforms Aficionado


Joined: 10 Mar 2003 Posts: 392 Location: Virginia
|
Posted: Mon May 31, 2010 3:37 pm Post subject: Drag and Drop between controls |
|
|
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 |
|
 |
It Took My Prozac KiXforms Supporter

Joined: 15 Feb 2005 Posts: 64
|
Posted: Fri Jun 04, 2010 2:43 am Post subject: |
|
|
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 |
|
 |
Bonji KiXforms Aficionado


Joined: 10 Mar 2003 Posts: 392 Location: Virginia
|
Posted: Thu Jul 22, 2010 4:45 pm Post subject: |
|
|
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 |
|
 |
It Took My Prozac KiXforms Supporter

Joined: 15 Feb 2005 Posts: 64
|
Posted: Mon Jul 26, 2010 11:32 pm Post subject: |
|
|
No worries  |
|
| Back to top |
|
 |
|