Type | Description | |||
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 |
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.
// OLEStartDrag event is not supported. Use the DragEnter,DragLeave,DragOver, DragDrop ... events. // OLEStartDrag event is not supported. Use the DragEnter,DragLeave,DragOver, DragDrop ... events. |
private void OLEStartDrag(object sender, AxEXLISTLib._IListEvents_OLEStartDragEvent e) { } void OnOLEStartDrag(LPDISPATCH Data,long FAR* AllowedEffects) { } void __fastcall OLEStartDrag(TObject *Sender,Exlistlib_tlb::IExDataObject *Data,long * AllowedEffects) { } procedure OLEStartDrag(ASender: TObject; Data : IExDataObject;var AllowedEffects : Integer); begin end; procedure OLEStartDrag(sender: System.Object; e: AxEXLISTLib._IListEvents_OLEStartDragEvent); begin end; begin event OLEStartDrag(oleobject Data,long AllowedEffects) end event OLEStartDrag Private Sub OLEStartDrag(ByVal sender As System.Object, ByVal e As AxEXLISTLib._IListEvents_OLEStartDragEvent) Handles OLEStartDrag End Sub Private Sub OLEStartDrag(ByVal Data As EXLISTLibCtl.IExDataObject,AllowedEffects As Long) End Sub Private Sub OLEStartDrag(ByVal Data As Object,AllowedEffects As Long) End Sub LPARAMETERS Data,AllowedEffects PROCEDURE OnOLEStartDrag(oList,Data,AllowedEffects) RETURN |
<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.List.1::IExDataObject,AllowedEffects as N) end function function nativeObject_OLEStartDrag(Data,AllowedEffects) 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 VC sample copies the selected items to the clipboard, as soon as the user starts dragging the items:
#import <exlist.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 OnOLEStartDragList1(LPDISPATCH Data, long FAR* AllowedEffects) { CItems items = m_list.GetItems(); long nCount = items.GetSelectCount(), nColumnCount = m_list.GetColumns().GetCount(); if ( nCount > 0 ) { *AllowedEffects = /*exOLEDropEffectCopy */ 1; EXLISTLib::IExDataObjectPtr spData( Data ); if ( spData !=NULL ) { CString strData; for ( long i = 0; i < nCount; i++ ) { long nItem = items.GetSelectedItem( i ); for ( long j = 0; j < nColumnCount; j++ ) strData += V2S( &items.GetCaption( nItem, COleVariant( j ) ) ) + "\t"; } strData += "\r\n"; spData->SetData( COleVariant( strData ), COleVariant( (long)EXLISTLib::exCFText) ); } } }
The sample saves data as CF_TEXT format ( EXLISTLib::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 exlist.dll file is located in another place than your system folder, the path to the exlist.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 AxList1_OLEStartDrag(ByVal sender As Object, ByVal e As AxEXLISTLib._IListEvents_OLEStartDragEvent) Handles AxList1.OLEStartDrag With AxList1.Items If (.SelectCount > 0) Then e.allowedEffects = 1 'exOLEDropEffectCopy Dim i As Integer, j As Integer, strData As String, nColumnCount As Long = AxList1.Columns.Count For i = 0 To .SelectCount - 1 For j = 0 To nColumnCount - 1 strData = strData + .Caption(.SelectedItem(i), j) + Chr(Keys.Tab) Next Next strData = strData + vbCrLf e.data.SetData(strData, EXLISTLib.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 axList1_OLEStartDrag(object sender, AxEXLISTLib._IListEvents_OLEStartDragEvent e) { int nCount = axList1.Items.SelectCount; if ( nCount > 0 ) { int nColumnCount = axList1.Columns.Count; e.allowedEffects = /*exOLEDropEffectCopy*/ 1; string strData = ""; for ( int i =0 ; i < nCount; i++ ) { for ( int j = 0; j < nColumnCount; j++ ) { object strCell = axList1.Items.get_Caption(axList1.Items.get_SelectedItem(i), j); strData += ( strCell != null ? strCell.ToString() : "" ) + "\t"; } strData += "\r\n"; } e.data.SetData( strData, EXLISTLib.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.List1.Items if ( .SelectCount() > 0 ) allowedeffects = 1 && exOLEDropEffectCopy sData = "" nColumnCount = thisform.List1.Columns.Count for i = 0 to .SelectCount - 1 for j = 0 to nColumnCount sData = sData + .Caption( .SelectedItem(i), j ) + chr(9) next sData = sData + chr(10)+ chr(13) next data.SetData( sData, 1 ) && exCFText endif endwith