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: Use the Background(exDragDropBefore) property to specify the visual appearance for the dragging items, before painting the items. Use the Background(exDragDropAfter) property to specify the visual appearance for the dragging items, after painting the items. Use the Background(exDragDropList) property to specify the graphic feedback for the item from the cursor, while the OLE drag and drop operation is running.  

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.

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, AxEXTREELib._ITreeEvents_OLEStartDragEvent e)
{
}

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

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

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

procedure OLEStartDrag(sender: System.Object; e: AxEXTREELib._ITreeEvents_OLEStartDragEvent);
begin
end;

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

Private Sub OLEStartDrag(ByVal sender As System.Object, ByVal e As AxEXTREELib._ITreeEvents_OLEStartDragEvent) Handles OLEStartDrag
End Sub

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

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

LPARAMETERS Data,AllowedEffects

PROCEDURE OnOLEStartDrag(oTree,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.Tree.1::IExDataObject,AllowedEffects as N)
end function

function nativeObject_OLEStartDrag(Data,AllowedEffects)
return

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

The first step is if you want to be able to drag items from your exTree 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:

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

Private Sub Tree1_OLEStartDrag(Index As Integer, ByVal Data As EXTREELibCtl.IExDataObject, AllowedEffects As Long)

    ' We are going to add two clipboard formats: text and "EXTREE" 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 Tree1(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 (Tree1(Index).Items.ItemParent(Tree1(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("EXTREE")

End Sub

The code fills data for  two types of clipboard formats: text ( CF_TEXT ) and "EXTREE" 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 Tree1_OLEDragDrop(Index As Integer, ByVal Data As EXTREELibCtl.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("EXTREE"))) 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("EXTREE"))
        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
        Tree1(Index).Visible = False
        With Tree1(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
        Tree1(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 <extree.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 OnOLEStartDragTree1(LPDISPATCH Data, long FAR* AllowedEffects) 
{
	CItems items = m_tree.GetItems();
	long nCount = items.GetSelectCount(), nColumnCount = m_tree.GetColumns().GetCount();
	if ( nCount > 0 )
	{
		*AllowedEffects = /*exOLEDropEffectCopy */ 1;
		EXTREELib::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)EXTREELib::exCFText) );
		}
	}
}

The sample saves data as CF_TEXT format ( EXTREELib::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 extree.dll file is located in another place than your system folder, the path to the extree.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 AxTree1_OLEStartDrag(ByVal sender As Object, ByVal e As AxEXTREELib._ITreeEvents_OLEStartDragEvent) Handles AxTree1.OLEStartDrag
    With AxTree1.Items
        If (.SelectCount > 0) Then
            e.allowedEffects = 1 'exOLEDropEffectCopy
            Dim i As Integer, j As Integer, strData As String, nColumnCount As Long = AxTree1.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, EXTREELib.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 axTree1_OLEStartDrag(object sender, AxEXTREELib._ITreeEvents_OLEStartDragEvent e)
{
	int nCount = axTree1.Items.SelectCount;
	if ( nCount > 0 )
	{
		int nColumnCount = axTree1.Columns.Count;
		e.allowedEffects = /*exOLEDropEffectCopy*/ 1;
		string strData = "";
		for ( int i =0 ; i < nCount; i++ )
		{
			for ( int j = 0; j < nColumnCount; j++ )
			{
				object strCell = axTree1.Items.get_CellCaption(axTree1.Items.get_SelectedItem(i), j);
				strData +=  ( strCell != null ? strCell.ToString() : "" ) + "\t";
			}
			strData += "\r\n";
		}
		e.data.SetData( strData, EXTREELib.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.Tree1.Items
	if ( .SelectCount() > 0 )
		allowedeffects = 1 && exOLEDropEffectCopy
		sData = ""
		nColumnCount = thisform.Tree1.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

 


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