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 |
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. Use the AutoDrag property to specify what the control does when the user clicks and drag the items.
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 exG2antt control is the same as in other
controls. To start accepting drag and drop sources the exG2antt control should
have the OLEDropMode to exOLEDropManual.
Once that is is set, the exG2antt starts accepting any drag and drop
sources.
The first step is if you want to be able to drag items from your exG2antt
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:
// 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, AxEXG2ANTTLib._IG2anttEvents_OLEStartDragEvent e) { } void OnOLEStartDrag(LPDISPATCH Data,long FAR* AllowedEffects) { } void __fastcall OLEStartDrag(TObject *Sender,Exg2anttlib_tlb::IExDataObject *Data,long * AllowedEffects) { } procedure OLEStartDrag(ASender: TObject; Data : IExDataObject;var AllowedEffects : Integer); begin end; procedure OLEStartDrag(sender: System.Object; e: AxEXG2ANTTLib._IG2anttEvents_OLEStartDragEvent); begin end; begin event OLEStartDrag(oleobject Data,long AllowedEffects) end event OLEStartDrag Private Sub OLEStartDrag(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_OLEStartDragEvent) Handles OLEStartDrag End Sub Private Sub OLEStartDrag(ByVal Data As EXG2ANTTLibCtl.IExDataObject,AllowedEffects As Long) End Sub Private Sub OLEStartDrag(ByVal Data As Object,AllowedEffects As Long) End Sub LPARAMETERS Data,AllowedEffects PROCEDURE OnOLEStartDrag(oG2antt,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.G2antt.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 G2antt1_OLEStartDrag(Index As Integer, ByVal Data As EXG2ANTTLibCtl.IExDataObject, AllowedEffects As Long) ' We are going to add two clipboard formats: text and "EXG2ANTT" 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 G2antt1(Index) s = Index & vbCrLf ' Saves the source For n = 0 To .Columns.Count - 1 s = s & .Items.CellValue(.Items.SelectedItem(0), n) & vbCrLf Next End With AllowedEffects = 0 ' Checks whether the selected item has a parent If (G2antt1(Index).Items.ItemParent(G2antt1(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("EXG2ANTT") End Sub
The code fills data for two types of clipboard formats: text ( CF_TEXT ) and "EXG2ANTT" 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 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) ' 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("EXG2ANTT"))) 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("EXG2ANTT")) 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 G2antt1(Index).Visible = False With G2antt1(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.CellValue(i, n) = Mid(s, nCur, nnCur - nCur) nCur = nnCur + Len(vbCrLf) Next .Items.CellImage(i, "EmployeeID") = Int(.Items.CellValue(i, "EmployeeID")) .Items.SetParent i, h(Index, Int(.Items.CellValue(i, "EmployeeID")) - 1) .Items.EnsureVisibleItem i .EndUpdate End With G2antt1(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 <exg2antt.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 OnOLEStartDragG2antt1(LPDISPATCH Data, long FAR* AllowedEffects) { CItems items = m_g2antt.GetItems(); long nCount = items.GetSelectCount(), nColumnCount = m_g2antt.GetColumns().GetCount(); if ( nCount > 0 ) { *AllowedEffects = /*exOLEDropEffectCopy */ 1; EXG2ANTTLib::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.GetCellValue( vtItem, COleVariant( j ) ) ) + "\t"; } strData += "\r\n"; spData->SetData( COleVariant( strData ), COleVariant( (long)EXG2ANTTLib::exCFText) ); } } }
The sample saves data as CF_TEXT format ( EXG2ANTTLib::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 exg2antt.dll file is located in another place than your system folder, the path to the exg2antt.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 AxG2antt1_OLEStartDrag(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_OLEStartDragEvent) Handles AxG2antt1.OLEStartDrag With AxG2antt1.Items If (.SelectCount > 0) Then e.allowedEffects = 1 'exOLEDropEffectCopy Dim i As Integer, j As Integer, strData As String, nColumnCount As Long = AxG2antt1.Columns.Count For i = 0 To .SelectCount - 1 For j = 0 To nColumnCount - 1 strData = strData + .CellValue(.SelectedItem(i), j) + Chr(Keys.Tab) Next Next strData = strData + vbCrLf e.data.SetData(strData, EXG2ANTTLib.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 axG2antt1_OLEStartDrag(object sender, AxEXG2ANTTLib._IG2anttEvents_OLEStartDragEvent e) { int nCount = axG2antt1.Items.SelectCount; if ( nCount > 0 ) { int nColumnCount = axG2antt1.Columns.Count; e.allowedEffects = /*exOLEDropEffectCopy*/ 1; string strData = ""; for ( int i =0 ; i < nCount; i++ ) { for ( int j = 0; j < nColumnCount; j++ ) { object strCell = axG2antt1.Items.get_CellValue(axG2antt1.Items.get_SelectedItem(i), j); strData += ( strCell != null ? strCell.ToString() : "" ) + "\t"; } strData += "\r\n"; } e.data.SetData( strData, EXG2ANTTLib.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.G2antt1.Items if ( .SelectCount() > 0 ) allowedeffects = 1 && exOLEDropEffectCopy sData = "" nColumnCount = thisform.G2antt1.Columns.Count for i = 0 to .SelectCount - 1 for j = 0 to nColumnCount sData = sData + .CellValue( .SelectedItem(i), j ) + chr(9) next sData = sData + chr(10)+ chr(13) next data.SetData( sData, 1 ) && exCFText endif endwith