event OLEStartDrag (Data as ExDataObject, AllowedEffects as Long)
Occurs when the OLEDrag method is called.

TypeDescription
Data as ExDataObject An ExDataObject object containing formats that the source will provide and, optionally, the data for those formats. If no data is contained in the ExDataObject, it is provided when the control calls the GetData method. The programmer should provide the values for this parameter in this event. The SetData and Clear methods cannot be used here.
AllowedEffects as Long A long containing the effects that the source component supports. The possible values are listed in Settings. The programmer should provide the values for this parameter in this event
In the /NET Assembly, you have to use the DragEnter event as explained here: The settings for AllowEffects are:

The source component should logically Or together the supported values and places the result in the AllowedEffects parameter. The target component can use this value to determine the appropriate action (and what the appropriate user feedback should be). You may wish to defer putting data into the ExDataObject object until the target component requests it. This allows the source component to save time.  If the user does not load any formats into the ExDataObject, then the drag/drop operation is canceled. Use exCFFiles and Files property to add files to the drag and drop data object.

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

The first step is if you want to be able to drag items from your exGrid 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 can be changed only in the OLEStartDrag event. The OLE_StartDrag event is fired when user is about to drag items from the control. The AllowedEffect parameter and SetData property must be set to continue drag and drop operation, as in the following samples:

Syntax for OLEStartDrag event, /NET version, on:

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

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

Syntax for OLEStartDrag event, /COM version, on:

private void OLEStartDrag(object sender, AxEXGRIDLib._IGridEvents_OLEStartDragEvent e)
{
}

void OnOLEStartDrag(LPDISPATCH Data,long FAR* AllowedEffects)
{
}

void __fastcall OLEStartDrag(TObject *Sender,Exgridlib_tlb::IExDataObject *Data,long * AllowedEffects)
{
}

procedure OLEStartDrag(ASender: TObject; Data : IExDataObject;var AllowedEffects : Integer);
begin
end;

procedure OLEStartDrag(sender: System.Object; e: AxEXGRIDLib._IGridEvents_OLEStartDragEvent);
begin
end;

begin event OLEStartDrag(oleobject Data,long AllowedEffects)
end event OLEStartDrag

Private Sub OLEStartDrag(ByVal sender As System.Object, ByVal e As AxEXGRIDLib._IGridEvents_OLEStartDragEvent) Handles OLEStartDrag
End Sub

Private Sub OLEStartDrag(ByVal Data As EXGRIDLibCtl.IExDataObject,AllowedEffects As Long)
End Sub

Private Sub OLEStartDrag(ByVal Data As Object,AllowedEffects As Long)
End Sub

LPARAMETERS Data,AllowedEffects

PROCEDURE OnOLEStartDrag(oGrid,Data,AllowedEffects)
RETURN

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

<SCRIPT EVENT="OLEStartDrag(Data,AllowedEffects)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function OLEStartDrag(Data,AllowedEffects)
End Function
</SCRIPT>

Procedure OnComOLEStartDrag Variant llData Integer llAllowedEffects
	Forward Send OnComOLEStartDrag llData llAllowedEffects
End_Procedure

METHOD OCX_OLEStartDrag(Data,AllowedEffects) CLASS MainDialog
RETURN NIL

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

function OLEStartDrag as v (Data as OLE::Exontrol.Grid.1::IExDataObject,AllowedEffects as N)
end function

function nativeObject_OLEStartDrag(Data,AllowedEffects)
return

The following VB sample drags data from a control to another, by registering a new clipboard format:

Private Sub Grid1_OLEStartDrag(Index As Integer, ByVal Data As EXGRIDLibCtl.IExDataObject, AllowedEffects As Long)

    ' We are going to add two clipboard formats: text and "EXGRID" clipboard format.
    ' We need to use RegisterClipboardFormat API function in order to register our
    ' clipboard format. One cliboard format is enough, but the sample shows
    ' how to filter in OLEDragDrop event the other clipboard formats

    ' Builds a string that contains each cell's caption on a new line
    Dim n As Long
    Dim s As String
    With Grid1(Index)
        s = Index & vbCrLf ' Saves the source
        For n = 0 To .Columns.Count - 1
            s = s & .Items.CellCaption(.Items.SelectedItem(0), n) & vbCrLf
        Next
    End With

    AllowedEffects = 0
    ' Checks whether the selected item has a parent
    If (Grid1(Index).Items.ItemParent(Grid1(Index).Items.SelectedItem(0)) <> 0) Then
        AllowedEffects = 1
    End If
    ' Sets the text clipboard format
    Data.SetData s, exCFText

    ' Builds an array of bytes, and copy there all characters in the s string.
    ' Passes the array to the SetData method.
    ReDim v(Len(s)) As Byte
    For n = 0 To Len(s) - 1
        v(n) = Asc(Mid(s, n + 1, 1))
    Next
    Data.SetData v, RegisterClipboardFormat("EXGRID")

End Sub

The code fills data for  two types of clipboard formats: text ( CF_TEXT ) and "EXGRID" registered clipboard format. The registered clipboard format must be an array of bytes. As you can see we have used the RegisterClipboardFormat API function, and it should be declared like:

Private Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Integer

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 gets as argument an object Data that stores the drag and drop information. The next sample shows how handle the OLEDragDrop event:

Private Sub Grid1_OLEDragDrop(Index As Integer, ByVal Data As EXGRIDLibCtl.IExDataObject, Effect As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' Checks whether the clipboard format is our. Since we have registered the clipboard in the
    ' OLEStartData format we now its format, so we can handle this type of clip formats.
    If (Data.GetFormat(RegisterClipboardFormat("EXGRID"))) Then
        ' Builds the saved string from the array passed
        Dim s As String
        Dim v() As Byte
        Dim n As Integer
        v = Data.GetData(RegisterClipboardFormat("EXGRID"))
        For n = LBound(v) To UBound(v)
            s = s + Chr(v(n))
        Next
        Debug.Print s

        'Adds a new item to the control, and sets the cells captions like we saved, line by line
        Grid1(Index).Visible = False
        With Grid1(Index)
            .BeginUpdate
            Dim i As HITEM
            Dim item As String
            Dim nCur As Long
            i = .Items.AddItem()
            nCur = InStr(1, s, vbCrLf) + Len(vbCrLf) ' Jumps the source
            For n = 0 To .Columns.Count - 1
                Dim nnCur As Long
                nnCur = InStr(nCur, s, vbCrLf)
                .Items.CellCaption(i, n) = Mid(s, nCur, nnCur - nCur)
                nCur = nnCur + Len(vbCrLf)
            Next
            .Items.CellImage(i, "EmployeeID") = Int(.Items.CellCaption(i, "EmployeeID"))
            .Items.SetParent i, h(Index, Int(.Items.CellCaption(i, "EmployeeID")) - 1)
            .Items.EnsureVisibleItem i
            .EndUpdate
        End With
        Grid1(Index).Visible = True
    End If
End Sub

The following VC sample copies the selected items to the clipboard, as soon as the user starts dragging the items:

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

#include "Items.h"
#include "Columns.h"

static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
	if ( pv )
	{
		if ( pv->vt == VT_ERROR )
			return szDefault;

		COleVariant vt;
		vt.ChangeType( VT_BSTR, pv );
		return V_BSTR( &vt );
	}
	return szDefault;
}

void OnOLEStartDragGrid1(LPDISPATCH Data, long FAR* AllowedEffects) 
{
	CItems items = m_grid.GetItems();
	long nCount = items.GetSelectCount(), nColumnCount = m_grid.GetColumns().GetCount();
	if ( nCount > 0 )
	{
		*AllowedEffects = /*exOLEDropEffectCopy */ 1;
		EXGRIDLib::IExDataObjectPtr spData( Data );
		if ( spData !=NULL )
		{
			CString strData;
			for ( long i = 0; i < nCount; i++ )
			{
				COleVariant vtItem( items.GetSelectedItem( i ) );
				for ( long j = 0; j < nColumnCount; j++ )
					strData += V2S( &items.GetCellCaption( vtItem, COleVariant( j ) ) ) + "\t";
			}
			strData += "\r\n";
			spData->SetData( COleVariant( strData ), COleVariant( (long)EXGRIDLib::exCFText) );
		}
	}
}

The sample saves data as CF_TEXT format ( EXGRIDLib::exCFText ). The data is a text, where each item is separated by "\r\n" ( new line ), and each cell is separated by "\t" ( TAB charcater ). Of course, data can be saved as you want. The sample only gives an idea of what and how it could be done. The sample uses the #import statement to import the control's type library, including definitions for ExDataObject and ExDataObjectFiles that are required to fill data to be dragged. If your exgrid.dll file is located in another place than your system folder, the path to the exgrid.dll file needs to be specified, else compiler errors occur.

The following VB.NET sample copies the selected items to the clipboard, as soon as the user starts dragging the items:

Private Sub AxGrid1_OLEStartDrag(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_OLEStartDragEvent) Handles AxGrid1.OLEStartDrag
    With AxGrid1.Items
        If (.SelectCount > 0) Then
            e.allowedEffects = 1 'exOLEDropEffectCopy
            Dim i As Integer, j As Integer, strData As String, nColumnCount As Long = AxGrid1.Columns.Count
            For i = 0 To .SelectCount - 1
                For j = 0 To nColumnCount - 1
                    strData = strData + .CellCaption(.SelectedItem(i), j) + Chr(Keys.Tab)
                Next
            Next
            strData = strData + vbCrLf
            e.data.SetData(strData, EXGRIDLib.exClipboardFormatEnum.exCFText)
        End If
    End With
End Sub

The following C# sample copies the selected items to the clipboard, as soon as the user starts dragging the items:

private void axGrid1_OLEStartDrag(object sender, AxEXGRIDLib._IGridEvents_OLEStartDragEvent e)
{
	int nCount = axGrid1.Items.SelectCount;
	if ( nCount > 0 )
	{
		int nColumnCount = axGrid1.Columns.Count;
		e.allowedEffects = /*exOLEDropEffectCopy*/ 1;
		string strData = "";
		for ( int i =0 ; i < nCount; i++ )
		{
			for ( int j = 0; j < nColumnCount; j++ )
			{
				object strCell = axGrid1.Items.get_CellCaption(axGrid1.Items.get_SelectedItem(i), j);
				strData +=  ( strCell != null ? strCell.ToString() : "" ) + "\t";
			}
			strData += "\r\n";
		}
		e.data.SetData( strData, EXGRIDLib.exClipboardFormatEnum.exCFText );
	}
}

The following VFP sample copies the selected items to the clipboard, as soon as the user starts dragging the items:

*** ActiveX Control Event ***
LPARAMETERS data, allowedeffects

local sData, nColumnCount, i, j
with thisform.Grid1.Items
	if ( .SelectCount() > 0 )
		allowedeffects = 1 && exOLEDropEffectCopy
		sData = ""
		nColumnCount = thisform.Grid1.Columns.Count
		for i = 0 to .SelectCount - 1
			for j = 0 to nColumnCount
				sData = sData + .CellCaption( .SelectedItem(i), j ) + chr(9)
			next
			sData = sData + chr(10)+ chr(13)
		next	
		data.SetData( sData, 1 ) && exCFText
	endif
endwith