Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

DataObject.SetData Method

Adds a supported format and possibly its data to a DataObject object.

Syntax

VB.NETobject.SetData([ ByVal Data As Object ] , [ ByVal Format As Object ] )
VBobject.SetData([ ByVal Data As Variant ] , [ ByVal Format As Variant ] )
C#.NETvoid object.SetData(object Data, object Format);
VC++HRESULT object->SetData(const _variant_t& Data = vtMissing, const _variant_t& Format = vtMissing);
CHRESULT object->raw_SetData(VARIANT Data, VARIANT Format);

object

A DataObject object.

Data

The data to be passed to the DataObject object. The Data argument is optional.

Format

The data format. The Format argument is optional.

FormatValueDescription
sftCFText1Text (as a String value)
sftCFBitmap2Bitmap (as Picture object)
sftCFMetafile3Metafile (as Picture object)
sftCFDIB8Device independent bitmap (as Picture object)
sftCFFiles15List of files. SetData cannot be used to supply data for this format. Use the Files collection instead.
sftCFRTF-16639Rich text format (as String value)

Comments

The SetData method adds a supported format and possibly its data to a DataObject object.

The Data argument is optional. This allows you to set several different formats that the source component can support without having to load the data separately for each format. Multiple formats are set by calling SetData several times, each time using a different format. If you wish to start fresh, use the Clear method to clear all data and format information from the DataObject.

The Format argument is also optional, but either the Data or Format argument must be specified. If Data is specified, but not Format, the format of the data is determined automatically. If this is unsuccessful, then an error is generated. When the target requests the data and a format was specified, but no data was provided, the source's OLESetData event occurs, and the source can then provide the requested data type.

It is possible for the GetData method and SetData method to use data formats other than those listed as valid Format argument, including user-defined formats registered with Windows via the RegisterClipboardFormat() API function. The SetData method requires the data to be in the form of a byte array when it does not recognize the data format specified. The GetData method always returns data in a byte array when it is in a format that it doesn't recognize, although this may be transparently converted into other data types, such as strings. The byte array returned by GetData will be larger than the actual data when running on some operating systems, with arbitrary bytes at the end of the array. This allocation of memory is often larger than is actually required for the data. Therefore, there may be extraneous bytes near the end of the allocated memory segment.

Examples

VB.NET

    F = AxSftDirectory1.CurrentFolder
    If Not F Is Nothing Then
        AxSftDirectory1.OLEDrag(False, True, -1, -1)
    End If
End Sub

Private Sub AxSftDirectory1_OLEStartDrag(ByVal sender As Object, ByVal e As AxSftDirectoryLib30._ISftDirectoryEvents_OLEStartDragEvent) Handles AxSftDirectory1.OLEStartDrag
    e.data.Clear()
    e.data.SetData(Nothing, SftOLEClipboardConstants.sftCFText)
    e.allowedEffects = 1 'vbDropEffectCopy
End Sub

Private Sub AxSftDirectory1_OLESetData(ByVal sender As Object, ByVal e As AxSftDirectoryLib30._ISftDirectoryEvents_OLESetDataEvent) Handles AxSftDirectory1.OLESetData
    If e.format = SftOLEClipboardConstants.sftCFText Then
        e.data.SetData("We're dragging a text string - """ & AxSftDirectory1.CurrentFolder.Name & """ - drop it in Write, Word (for example)", SftOLEClipboardConstants.sftCFText)
    End If

VB6

    If Not F Is Nothing Then
        SftDirectory1.OLEDrag False, True, -1, -1
    End If
End Sub

Private Sub SftDirectory1_OLEStartDrag(Data As SftDirectoryLib30.DataObject, _
        AllowedEffects As Long)
    Data.Clear
    Data.SetData , sftCFText
    AllowedEffects = vbDropEffectCopy
End Sub

Private Sub SftDirectory1_OLESetData(Data As SftDirectoryLib30.DataObject, Format As Integer)
    If Format = sftCFText Then
        Data.SetData "We're dragging a text string - """ & SftDirectory1.CurrentFolder.Name & """ - drop it in Write, Word (for example)", sftCFText
    End If

C#

    if (f != null) {
        axSftDirectory1.OLEDrag(false, true, -1, -1);
    }
}

private void axSftDirectory1_OLEStartDrag(object sender, AxSftDirectoryLib30._ISftDirectoryEvents_OLEStartDragEvent e)
{
    e.data.Clear();
    e.data.SetData(null, SftOLEClipboardConstants.sftCFText);
    e.allowedEffects = 1; //vbDropEffectCopy
}

private void axSftDirectory1_OLESetData(object sender, AxSftDirectoryLib30._ISftDirectoryEvents_OLESetDataEvent e)
{
    if (e.format == (short) SftOLEClipboardConstants.sftCFText) {
        e.data.SetData("We're dragging a text string - \"" + axSftDirectory1.CurrentFolder.Name + "\" - drop it in Write, Word (for example)", SftOLEClipboardConstants.sftCFText);

C++

        m_vDir1->OLEDrag(VARIANT_FALSE, VARIANT_TRUE, -1, -1);
}

void COLEDragDlg::OnOLEStartDragSftDirectory1(LPDISPATCH FAR* Data, long FAR* AllowedEffects)
{
    IVDMDataObjectPtr pData(*Data);

    pData->Clear();
    pData->SetData(_variant_t(), _variant_t((short) sftCFText));
    *AllowedEffects = 1; //vbDropEffectCopy
}

void COLEDragDlg::OnOLESetDataSftDirectory1(LPDISPATCH FAR* Data, short FAR* Format)
{
    IVDMDataObjectPtr pData(*Data);

See Also DataObject Object | Object Hierarchy


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.