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 AddItem method to add a new item to the control. Use the InsertItem method to insert a new child item. 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, AxEXG2ANTTLib._IG2anttEvents_OLEDragDropEvent e)
{
}

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

void __fastcall OLEDragDrop(TObject *Sender,Exg2anttlib_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: AxEXG2ANTTLib._IG2anttEvents_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 AxEXG2ANTTLib._IG2anttEvents_OLEDragDropEvent) Handles OLEDragDrop
End Sub

Private Sub OLEDragDrop(ByVal Data As EXG2ANTTLibCtl.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(oG2antt,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.G2antt.1::IExDataObject,Effect as N,Button as N,Shift as N,X as OLE::Exontrol.G2antt.1::OLE_XPOS_PIXELS,Y as OLE::Exontrol.G2antt.1::OLE_YPOS_PIXELS)
end function

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

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 G2antt1_OLEDragDrop(Index As Integer, ByVal Data As EXG2ANTTLibCtl.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
        G2antt1(Index).Visible = False
        With G2antt1(Index)
        .BeginUpdate
            Dim i As HITEM
            i = .Items.AddItem(strFile)
            .Items.EnsureVisibleItem i
        .EndUpdate
        End With
        G2antt1(Index).Visible = True
    End If
End Sub

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

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

#include "Items.h"
void OnOLEDragDropG2antt1(LPDISPATCH Data, long FAR* Effect, short Button, short Shift, long X, long Y) 
{
	EXG2ANTTLib::IExDataObjectPtr spData( Data );
	if ( spData != NULL )
		if ( spData->GetFormat( EXG2ANTTLib::exCFFiles ) )
		{
			CItems items = m_g2antt.GetItems();
			// Gets the handle of the item where the files will be inserted
			long c = 0, h = 0, nParentItem = m_g2antt.GetItemFromPoint( X, Y, &c, &h );
			if ( nParentItem == 0 )
				if ( c != 0 )
					nParentItem = items.GetCellItem( c );
			EXG2ANTTLib::IExDataObjectFilesPtr spFiles( spData->Files );
			if ( spFiles->Count > 0 )
			{
				m_g2antt.BeginUpdate();
				COleVariant vtMissing; vtMissing.vt = VT_ERROR;
				for ( long i = 0; i < spFiles->Count; i++ )
					items.InsertItem( nParentItem, vtMissing, COleVariant( spFiles->GetItem( i ).operator const char *() ) );
				if ( nParentItem )
					items.SetExpandItem( nParentItem, TRUE );
				m_g2antt.EndUpdate();
			}

		}
}

The #import statement imports definition for the ExDataObject and ExDataObjectFiles objects. If the exg2antt.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 AxG2antt1_OLEDragDrop(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_OLEDragDropEvent) Handles AxG2antt1.OLEDragDrop
    If e.data.GetFormat(EXG2ANTTLib.exClipboardFormatEnum.exCFFiles) Then
        If (e.data.Files.Count > 0) Then
            AxG2antt1.BeginUpdate()
            With AxG2antt1.Items
                Dim iParent As Integer, c As Integer, hit As EXG2ANTTLib.HitTestInfoEnum
                iParent = AxG2antt1.get_ItemFromPoint(e.x, e.y, c, hit)
                If iParent = 0 Then
                    If Not c = 0 Then
                        iParent = .CellItem(c)
                    End If
                End If
                Dim i As Long
                For i = 0 To e.data.Files.Count - 1
                    .InsertItem(iParent, , e.data.Files(i))
                Next
                If Not (iParent = 0) Then
                    .ExpandItem(iParent) = True
                End If
            End With
            AxG2antt1.EndUpdate()
        End If
    End If
End Sub

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

private void axG2antt1_OLEDragDrop(object sender, AxEXG2ANTTLib._IG2anttEvents_OLEDragDropEvent e)
{
	if ( e.data.GetFormat( Convert.ToInt16(EXG2ANTTLib.exClipboardFormatEnum.exCFFiles) ) )
		if ( e.data.Files.Count > 0 )
		{
			EXG2ANTTLib.HitTestInfoEnum hit;
			int c = 0, iParent = axG2antt1.get_ItemFromPoint( e.x, e.y, out c, out hit );
			if ( iParent == 0 )
				if ( c != 0 )
					iParent = axG2antt1.Items.get_CellItem( c );

			axG2antt1.BeginUpdate();
			for ( int i = 0; i < e.data.Files.Count; i++ )
				axG2antt1.Items.InsertItem( iParent,"", e.data.Files[i].ToString() );
			if ( iParent != 0 )
				axG2antt1.Items.set_ExpandItem( iParent, true );
			axG2antt1.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, iParent
c = 0
hit = 0
if ( data.GetFormat( 15 ) ) && exCFFiles
	if ( data.Files.Count() > 0 )
		with thisform.G2antt1.Items
			iParent = thisform.G2antt1.ItemFromPoint( x, y, @c, @hit )
			
			thisform.G2antt1.BeginUpdate()
			for i = 0 to data.files.Count() - 1
				.InsertItem( iParent, "", data.files(i) )
			next
			if ( iParent != 0 )
				.DefaultItem = iParent
				.ExpandItem( 0 ) = .t.
			endif
			thisform.G2antt1.EndUpdate()
		endwith	
	endif
endif

 


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