event OLEDragDrop (Data as ExDataObject, Effect as Long, Button as Integer, Shift as Integer, X as OLE_XPOS_PIXELS, Y as OLE_YPOS_PIXELS)
Occurs when a source component is dropped onto a target component when the source component determines that a drop can occur.

 TypeDescription 
   Data as ExDataObject An ExDataObject object containing formats that the source will provide and, in addition, possibly the data for those formats. If no data is contained in the ExDataObject, it is provided when the control calls the GetData method. The SetData and Clear methods cannot be used here.  
   Effect as Long A Long set by the target component identifying the action that has been performed (if any), thus allowing the source to take appropriate action if the component was moved (such as the source deleting the data). The possible values are listed in Remarks.  
   Button as Integer An integer which acts as a bit field corresponding to the state of a mouse button when it is depressed. The left button is bit 0, the right button is bit 1, and the middle button is bit 2. These bits correspond to the values 1, 2, and 4, respectively. It indicates the state of the mouse buttons; some, all, or none of these three bits can be set, indicating that some, all, or none of the buttons are depressed.  
   Shift as Integer An integer which acts as a bit field corresponding to the state of the SHIFT, CTRL, and ALT keys when they are depressed. The SHIFT key is bit 0, the CTRL key is bit 1, and the ALT key is bit 2. These bits correspond to the values 1, 2, and 4, respectively. The shift parameter indicates the state of these keys; some, all, or none of the bits can be set, indicating that some, all, or none of the keys are depressed. For example, if both the CTRL and ALT keys were depressed, the value of shift would be 6.  
   X as OLE_XPOS_PIXELS A single that specifies the current X location of the mouse pointer. The X value is always expressed in container coordinates  
   Y as OLE_YPOS_PIXELS A single that specifies the current Y location of the mouse pointer. The Y value is always expressed in container coordinates.  
In the /NET Assembly, you have to use the DragDrop event as explained here:

The OLEDragDrop event is fired when the user has dropped files or clipboard information into the control. Use the OLEDropMode property on exOLEDropManual to enable OLE drop and drop support. Use the ItemFromPoint property to get the item from point. Use the ColumnFromPoint property to get the column from point. Use the Add method to add a new item to the control. Use the ItemPosition property to specify the item's position.

The settings for Effect are:

Syntax for OLEDragDrop event, /NET version, on:

// OLEDragDrop event is not supported. Use the DragEnter,DragLeave,DragOver, DragDrop ... events.

// OLEDragDrop event is not supported. Use the DragEnter,DragLeave,DragOver, DragDrop ... events.

Syntax for OLEDragDrop event, /COM version, on:

private void OLEDragDrop(object sender, AxEXLISTLib._IListEvents_OLEDragDropEvent e)
{
}

void OnOLEDragDrop(LPDISPATCH Data,long FAR* Effect,short Button,short Shift,long X,long Y)
{
}

void __fastcall OLEDragDrop(TObject *Sender,Exlistlib_tlb::IExDataObject *Data,long * Effect,short Button,short Shift,int X,int Y)
{
}

procedure OLEDragDrop(ASender: TObject; Data : IExDataObject;var Effect : Integer;Button : Smallint;Shift : Smallint;X : Integer;Y : Integer);
begin
end;

procedure OLEDragDrop(sender: System.Object; e: AxEXLISTLib._IListEvents_OLEDragDropEvent);
begin
end;

begin event OLEDragDrop(oleobject Data,long Effect,integer Button,integer Shift,long X,long Y)
end event OLEDragDrop

Private Sub OLEDragDrop(ByVal sender As System.Object, ByVal e As AxEXLISTLib._IListEvents_OLEDragDropEvent) Handles OLEDragDrop
End Sub

Private Sub OLEDragDrop(ByVal Data As EXLISTLibCtl.IExDataObject,Effect As Long,ByVal Button As Integer,ByVal Shift As Integer,ByVal X As Single,ByVal Y As Single)
End Sub

Private Sub OLEDragDrop(ByVal Data As Object,Effect As Long,ByVal Button As Integer,ByVal Shift As Integer,ByVal X As Long,ByVal Y As Long)
End Sub

LPARAMETERS Data,Effect,Button,Shift,X,Y

PROCEDURE OnOLEDragDrop(oList,Data,Effect,Button,Shift,X,Y)
RETURN

Syntax for OLEDragDrop event, /COM version (others), on:

<SCRIPT EVENT="OLEDragDrop(Data,Effect,Button,Shift,X,Y)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function OLEDragDrop(Data,Effect,Button,Shift,X,Y)
End Function
</SCRIPT>

Procedure OnComOLEDragDrop Variant llData Integer llEffect Short llButton Short llShift OLE_XPOS_PIXELS llX OLE_YPOS_PIXELS llY
	Forward Send OnComOLEDragDrop llData llEffect llButton llShift llX llY
End_Procedure

METHOD OCX_OLEDragDrop(Data,Effect,Button,Shift,X,Y) CLASS MainDialog
RETURN NIL

// OLEDragDrop event is not supported. Use the DragEnter,DragLeave,DragOver, DragDrop ... events.

function OLEDragDrop as v (Data as OLE::Exontrol.List.1::IExDataObject,Effect as N,Button as N,Shift as N,X as OLE::Exontrol.List.1::OLE_XPOS_PIXELS,Y as OLE::Exontrol.List.1::OLE_YPOS_PIXELS)
end function

function nativeObject_OLEDragDrop(Data,Effect,Button,Shift,X,Y)
return

The idea of drag and drop in exList control is the same as in other controls. To start accepting drag and drop sources the exList control should have the OLEDropMode to exOLEDropManual. Once that is is set, the exList starts accepting any drag and drop sources.

The first step is if you want to be able to drag items from your exList control to other controls the idea is to handle the OLE_StartDrag event. The event passes an object ExDataObject (Data) as argument. The Data and AllowedEffects should be set inside of handler event. Here's a sample:

Private Sub List1_OLEStartDrag(ByVal Data As EXLISTLibCtl.IExDataObject, AllowedEffects As Long)
    Dim i As Long
    Dim str As String
    With List1.Items
        For i = 0 To .SelectCount - 1
            str = str + .Caption(.SelectedItem(i), 0)
            str = str + vbCrLf
        Next
        AllowedEffects = 1
        Data.SetData str, exCFText
    End With
End Sub

What the above code does? It takes each selected item from the exList source, and builds a string that will be passed to the clipboard object Data as text string. So, the clipboard data will contains text, so you will be able to drag the items to a text control. Of course the target controls should have enabled the OLE drag and drop features, and it depends on each control. The AllowedEffects = 1 specifies the type of cursor used in drag and drop operations. The value should be a combination of one of the exOLEDropEffectEnum type. Please check your environment browsed for the all possible values: 1 - Copy, 2 - Move, 0 - None, So, AllowedEffects = 1 specifies the "copy" cursor. If you don't set the AllowedEffects parameter, the cursor is by default None. There is no rule how you have to store the data into the clipboard Data object. It depends how you would like to do the drag and drop operations works.

The second step is accepting OLE drag and drop source objects. That means, if you would like to let your control accept drag and drop objects, you have to handle the OLEDragDrop event. It passes as argument an object Data that stores the drag and drop information. The next sample shows how to take each line saved into the data object and add for each line found a new item into your exList control:

Private Sub List2_OLEDragDrop(ByVal Data As Object, Effect As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
    Dim str As String
    str = Data.GetData(exCFText)
    if Not (Right(str, Len(vbCrLf)) = vbCrLf) Then
        str = str + vbCrLf
    End If
    With List2
        .BeginUpdate
        Dim c As Long, i As Long, n1 As Long, n2 As Long, nPos As Long
        While .Items.SelectCount <> 0
            .Items.SelectItem(.Items.SelectedItem(0)) = False
        Wend
        i = .ItemFromPoint(X / 15, Y / 15, c)
        If (i >= 0) Then
            nPos = .Items.ItemPosition(i)
        End If
        Debug.Print "Index = " & i
        n1 = 1
        n2 = InStr(n1, str, vbCrLf)
        While (n2 > 0)
            Dim n As Long
            n = .Items.Add(Mid(str, n1, n2 - n1))
            If .Items.Caption(n, 0) = "" Then
                .Items.ItemBreak(n) = DotLine
            End If
            If (i >= 0) Then
                .Items.ItemPosition(n) = nPos + 1
                nPos = nPos + 1
            End If
            .Items.SelectItem(n) = True
            n1 = n2 + Len(vbCrLf)
            n2 = InStr(n1, str, vbCrLf)
        Wend
        .EndUpdate
    End With
End Sub

The following VB sample adds a new item when the user drags a file ( Open the Windows Explorer, click and drag a file to the control ) :

Private Sub List1_OLEDragDrop(ByVal Data As EXLISTLibCtl.IExDataObject, Effect As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Data.GetFormat(exCFFiles) Then
        Data.GetData (exCFFiles)
        Dim strFile As String
        strFile = Data.Files(0)
        'Adds a new item to the control
        List1.Visible = False
        With List1
        .BeginUpdate
            Dim i As Long
            i = .Items.Add(strFile)
            .Items.EnsureVisibleItem i
        .EndUpdate
        End With
        List1.Visible = True
    End If
End Sub

The following VC sample inserts a child item for each file that user drags:

#import <exlist.dll> rename( "GetItems", "exGetItems" )

#include "Items.h"
void OnOLEDragDropList1(LPDISPATCH Data, long FAR* Effect, short Button, short Shift, long X, long Y) 
{
	EXLISTLib::IExDataObjectPtr spData( Data );
	if ( spData != NULL )
		if ( spData->GetFormat( EXLISTLib::exCFFiles ) )
		{
			CItems items = m_list.GetItems();
			long c = 0, h = 0, iFrom = m_list.GetItemFromPoint( X, Y, &c, &h );
			EXLISTLib::IExDataObjectFilesPtr spFiles( spData->Files );
			if ( spFiles->Count > 0 )
			{
				m_list.BeginUpdate();
				COleVariant vtMissing; vtMissing.vt = VT_ERROR;
				for ( long i = 0; i < spFiles->Count; i++ )
				{
					long h = items.Add( COleVariant( spFiles->GetItem( i ).operator const char *() ) );
					if ( i >= 0 )
						items.SetItemPosition( h, items.GetItemPosition(iFrom) );
				}
				m_list.EndUpdate();
			}
		}
}

The #import statement imports definition for the ExDataObject and ExDataObjectFiles objects. If the exlist.dll file is located in another folder than the system folder, the path to the file must be specified. The sample gets the item where the files were dragged and insert all files in that position, as child items, if case.

The following VB.NET sample inserts a child item for each file that user drags:

Private Sub AxList1_OLEDragDrop(ByVal sender As Object, ByVal e As AxEXLISTLib._IListEvents_OLEDragDropEvent) Handles AxList1.OLEDragDrop
    If e.data.GetFormat(EXLISTLib.exClipboardFormatEnum.exCFFiles) Then
        If (e.data.Files.Count > 0) Then
            AxList1.BeginUpdate()
            With AxList1.Items
                Dim c As Integer, hit As EXLISTLib.HitTestInfoEnum, iFrom As Integer = AxList1.get_ItemFromPoint(e.x, e.y, c, hit)
                Dim i As Long
                For i = 0 To e.data.Files.Count - 1
                    Dim newI As Integer = .Add(e.data.Files(i))
                    If (iFrom >= 0) Then
                        .ItemPosition(newI) = .ItemPosition(iFrom)
                    End If
                Next
            End With
            AxList1.EndUpdate()
        End If
    End If
End Sub

The following C# sample inserts a child item for each file that user drags:

private void axList1_OLEDragDrop(object sender, AxEXLISTLib._IListEvents_OLEDragDropEvent e)
{
	if (e.data.GetFormat(Convert.ToInt16(EXLISTLib.exClipboardFormatEnum.exCFFiles)))
		if (e.data.Files.Count > 0)
		{
			EXLISTLib.HitTestInfoEnum hit;
			int c = 0, iFrom = axList1.get_ItemFromPoint(e.x, e.y, out c, out hit);
			axList1.BeginUpdate();
			for (int i = 0; i < e.data.Files.Count; i++)
			{
				int newI = axList1.Items.Add(e.data.Files[i].ToString());
				if (iFrom >= 0)
					axList1.Items.set_ItemPosition(newI, axList1.Items.get_ItemPosition(iFrom));
			}
			axList1.EndUpdate();
		}
}

The following VFP sample inserts a child item for each file that user drags:

*** ActiveX Control Event ***
LPARAMETERS data, effect, button, shift, x, y

local c, hit, iFrom
c = 0
hit = 0
if ( data.GetFormat( 15 ) ) && exCFFiles
	if ( data.Files.Count() > 0 )
		with thisform.List1.Items
			iFrom = thisform.List1.ItemFromPoint( x, y, @c, @hit )
			thisform.List1.BeginUpdate()
			for i = 0 to data.files.Count() - 1
				local newI
				newI = .Add( data.files(i) )
				if ( iFrom >= 0 )
					.ItemPosition(newI) = .ItemPosition(iFrom)
				endif		
			next
			thisform.List1.EndUpdate()
		endwith	
	endif
endif

Send comments on this topic.
1999-2015 Exontrol.COM, Software. All rights reserved.