To set the control to receive drag/drop actions from other objects, set the AllowDrop property of the control to True. In the DragEnter event of the control set the e.Effect property to the appropriate value depending upon the type of object being dragged. NOTE: The e (event args) passed in to the DragEnter event contains the information describing the object being dragged. In the example below, the object being dragged is a dbiExplorerItem attached to the tag property of a picture box object.
Example:
VB.NET
Private Sub dbicExplorerBar_DragEnter(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles dbicExplorerBar.DragEnter
If e.Data.GetDataPresent(GetType(Dbi.WinControl.ExplorerBar.dbiExplorerItem)) Then
' There is an explorer item in the data being dragged. Allow copy.
e.Effect = DragDropEffects.Copy
Else
' There is no exploreritem in the data being dragged. Prohibit drop.
e.Effect = DragDropEffects.None
End If
End Sub
C#
private void dbicExplorerBar_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Dbi.WinControl.ExplorerBar.dbiExplorerItem)) == true)
{
// There is an explorer item in the data being dragged. Allow copy.
e.Effect = DragDropEffects.Copy;
}
else
{
// There is no exploreritem in the data being dragged. Prohibit drop.
e.Effect = DragDropEffects.None;
}
}
When an object is dropped on the dbicExplorerBar control, a DragDrop event is fired. NOTE: The DragDrop event fires in response to a drop action however it does not expose the List and/or List Item on which the drag/drop action took place. To add or insert the dropped item to the open list a flag is required to notify the dbicExplorerBar’s ItemOver event that a drop action has occurred so the appropriate add or insert action can take place in the list on which the drop action occurred. NOTE: The ItemOver event reports the list and the item over which the mouse is positioned. When a drop action occurs on the dbicExplorerBar control the DragDrop event fires first allowing a flag to be set; the ItemOver event fires next in which the List and Item over which the action took place can be evaluated and the appropriate add or insert action coded.
In the Form Class code create a variable to be used as a flag …
Example:
VB.NET
Public Class Form1
Dim itemDropped As Boolean 'Indicates when an item is dropped on the dbicExplorerBar control in _
the Multi-Column Drag and Drop Tab page
C#
public partial class Form1 : Form
{
Boolean itemDropped; // Indicates when an item is dropped on the dbicExplorerBar control in the Multi-
Column Drag and Drop Tab page
In the dbicExplorerBar DragDrop event code the setting of the flag to indicate a drop event has occurred …
VB.NET
Private Sub dbicExplorerBar_DragDrop(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles DbicExplorerBar.DragDrop
itemDropped = True 'Indicates to the ItemOver event that an item was dropped on the control
End Sub
C#
private void dbicExplorerBar_DragDrop(object sender, DragEventArgs e)
{
itemDropped = true; //Indicates to the ItemOver event that an item was dropped on the control
}
In the dbicExplorerBar ItemOver event code the completion of the drop event …
VB.NET
Private Sub DbicExplorerBar_ItemOver(ByVal sender As Object, ByVal e As _ Dbi.WinControl.ExplorerBar.ItemOverEventArgs) Handles DbicExplorerBar.ItemOver
'This event fires as the mouse passes over lists and items in the list.
'NOTE: The e object passed by the event contains information about the list and the item under the mouse.
If itemDropped Then 'If the ItemOver event was fired after an item was dropped
If e.ItemIndex > -1 Then 'If the drop occurred on an item in a list.
'Insert the dropped object at the location where the drop occurred.
Me.dbicExplorerBar.Lists(e.ListIndex).Items.Insert(e.ItemIndex, "Component Toolbox", 10)
Else 'The drop did not occur on an item in the list
'Add the dropped object to the end of the list.
Me.dbicExplorerBar.Lists(e.ListIndex).Items.Add("Component Toolbox", 10)
End If
itemDropped = False 'Reset the flag
End If
End Sub
C#
private void dbicExplorerBar_ItemOver(object sender, Dbi.WinControl.ExplorerBar.ItemOverEventArgs e)
{
// This event fires as the mouse passes over lists and items in the list.
// NOTE: The e object passed by the event contains information about the list and the item under the
mouse
if (itemDropped) //If the ItemOver event was fired after an item was dropped
{
if (e.ItemIndex > -1) //If the drop occurred on an item in a list.
{
//Insert the dropped object at the location where the drop occurred.
this.dbicExplorerBar.Lists[e.ListIndex].Items.Insert(e.ItemIndex, "Component Toolbox", 10);
}
else //The drop did not occur on an item in the list
{
//Add the dropped object to the end of the list.
this.dbicExplorerBar.Lists[e.ListIndex].Items.Add("Component Toolbox", 10);
}
itemDropped = false; //Reset the flag
}
}
NOTE: In the code above, the e arguments passed in to the event expose the List (ListIndex) and Item (ItemIndex) on which the mouse is over at the time drop occurred. In the case where no item was under the mouse the ItemIndex value reported is -1. In the case where the mouse is not over a list in the control at the time a drop action occurs the ItemOver event will not fire.