BeginDrag event
The BeginDrag event has different arguments for different
objects:
|
Object |
See |
|---|---|
|
ListView control |
|
|
TreeView control |
Syntax 1 For ListView controls
Description
Occurs when the user presses the left mouse button in the
ListView control and begins dragging.
Event ID
|
Event ID |
Objects |
|---|---|
|
pbm_lvnbegindrag |
ListView |
Parameters
|
Argument |
Description |
|---|---|
|
index |
Integer by value |
Return Values
Long. Return code choices (specify in
a RETURN statement):
-
0 Continue
processing
Usage
BeginDrag and BeginRightDrag events occur when the user presses
the mouse button and drags, whether or not dragging is enabled.
To enable dragging, you can:
-
Set the DragAuto property
to true. If the ListView’s DragAuto
property is true, a drag operation begins automatically
when the user clicks. -
Call the Drag function. If DragAuto
is false, then in the BeginDrag event script,
the programmer can call the Drag function to
begin the drag operation.
Dragging a ListView item onto another control causes its standard
drag events (DragDrop, DragEnter, DragLeave, and DragWithin) to
occur. The standard drag events occur for ListView when another
control is dragged within the borders of the ListView.
Examples
This example moves a ListView item from one ListView
to another. Ilvi_dragged_object is
a window instance variable whose type is ListViewItem. To copy the
item, omit the code that deletes it from the source ListView.
This code is in the BeginDrag event script of the source ListView:
|
1 |
// If the TreeView's DragAuto property is FALSE |
|
1 |
This.Drag(Begin!) |
|
1 |
|
1 |
This.GetItem(This.SelectedIndex(), & |
|
1 |
   ilvi_dragged_object) |
|
1 |
|
1 |
// To copy, rather than move, omit these two lines |
|
1 |
This.DeleteItem(This.SelectedIndex()) |
|
1 |
This.Arrange() |
This code is in the DragDrop event of the target
ListView:
|
1 |
This.AddItem(ilvi_dragged_object) |
|
1 |
This.Arrange() |
See Also
Syntax 2 For TreeView controls
Description
Occurs when the user presses the left mouse button on a label
in the TreeView control and begins dragging.
Event ID
|
Event ID |
Objects |
|---|---|
|
pbm_tvnbegindrag |
TreeView |
Parameters
|
Argument |
Description |
|---|---|
|
handle |
Long by value (handle |
Return Values
Long. Return code choices (specify in
a RETURN statement):
-
0 Continue
processing
Usage
BeginDrag and BeginRightDrag events occur when the user presses
the mouse button and drags, whether or not dragging is enabled.
To enable dragging, you can:
-
Set the DragAuto property
to true. If the TreeView’s DragAuto
property is true, a drag operation begins automatically
when the user clicks. -
Call the Drag function. If DragAuto
is false, then in the BeginDrag event script,
the programmer can call the Drag function to
begin the drag operation.
The user cannot drag a highlighted item.
Dragging a TreeView item onto another control causes the control’s
standard drag events (DragDrop, DragEnter, DragLeave, and DragWithin)
to occur. The standard drag events occur for TreeView when another
control is dragged within the borders of the TreeView.
Examples
This example moves the first TreeView item in the
source TreeView to another TreeView when the user drags there. Itvi_dragged_object is
a window instance variable whose type is TreeViewItem. To copy the
item, omit the code that deletes it from the source TreeView.
This code is in the BeginDrag event script of the source TreeView:
|
1 |
long itemnum |
|
1 |
|
1 |
// If the TreeView's DragAuto property is FALSE |
|
1 |
This.Drag(Begin!) |
|
1 |
itemnum = 1 |
|
1 |
This.GetItem(itemnum, itvi_dragged_object) |
|
1 |
|
1 |
// To copy, rather than move, omit these two lines |
|
1 |
This.DeleteItem(itemnum) |
|
1 |
This.SetRedraw(TRUE) |
This code is in the DragDrop event of the target
TreeView:
|
1 |
This.InsertItemLast(0, ilvi_dragged_object) |
|
1 |
This.SetRedraw(TRUE) |
Instead of deleting the item from the source TreeView immediately,
consider deleting it after the insertion in the DragDrop event succeeds.