Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

SetData Method, DataObject Object

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 (see SftOLEClipboardConstants). 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 DataObject.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 DataObject.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 DataObject.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 DataObject.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 DataObject.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

            If AxSftTree1.get_Item(curr).Expanded Then
                img = AxSftTree1.Items.ItemImageExpanded
            ElseIf AxSftTree1.get_Item(curr).DependentAllCount > 0 Then
                img = AxSftTree1.Items.ItemImageExpandable
            Else
                img = AxSftTree1.Items.ItemImageLeaf
            End If
        End If
        e.data.SetData(img.Picture, SftOLEClipboardConstants.sftCFDIB)
        e.data.SetData(img.Picture, SftOLEClipboardConstants.sftCFBitmap)
        e.allowedEffects = 3
    End Sub

    Private Sub DropTarget_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DropTarget.DragEnter
        If e.Data.GetDataPresent(DataFormats.Text, True) Or e.Data.GetDataPresent(DataFormats.Bitmap, True) Then
            e.Effect = DragDropEffects.Copy

VB6

    End If
End Sub


Private Sub SftTree1_OLEStartDrag(Data As SftTreeLib75.DataObject, AllowedEffects As Long)
    Dim curr As Integer
    curr = SftTree1.Items.Current
    ' cell text
    Data.SetData SftTree1.Cell(curr, 0).Text, vbCFText
    ' item picture
    If SftTree1.Item(curr).Image.Type = sftTypeIDispatch Then
        Data.SetData SftTree1.Item(curr).Image.Picture, vbCFDIB
    Else
        If SftTree1.Item(curr).Expanded Then
            Data.SetData SftTree1.Items.ItemImageExpanded.Picture, vbCFDIB
        ElseIf SftTree1.Item(curr).DependentAllCount > 0 Then

C#

        private void axSftTree1_OLEStartDrag(object sender, AxSftTreeLib75._DSftTreeEvents_OLEStartDragEvent e) {

            // This section demonstrates drag&drop) using OLE mechanisms built into this control
            // THIS CODE IS ONLY USED IF DRAGMETHOD IS SET TO  ( 3 - OLEDrag ) or SftTreeDragMethodConstants.dragSftTreeOLE

            int curr = axSftTree1.Items.Current;
            // cell text
            e.data.SetData(axSftTree1.get_Cell(curr, 0).Text, SftOLEClipboardConstants.sftCFText);
            // item picture
            SftPictureObject img = null;
            if (axSftTree1.get_Item(curr).Image.Type == SftPictureTypeConstants.sftTypeIDispatch) {
                img = axSftTree1.get_Item(curr).Image;
            } else {
                if (axSftTree1.get_Item(curr).Expanded)
                    img = axSftTree1.Items.ItemImageExpanded;
                else if (axSftTree1.get_Item(curr).DependentAllCount > 0)

C++

void CDragDropDlg::OnOLEStartDragSftTree1(LPDISPATCH FAR* Data, long FAR* AllowedEffects)
{
    IVDMDataObjectPtr pDataObject = *Data;
    ASSERT(pDataObject != NULL);

    long curr = m_vTree->Items->Current;
    // cell text
    pDataObject->SetData(_variant_t(m_vTree->Cell[curr][0]->Text), _variant_t((short)sftCFText));
    // item picture
    if (m_vTree->Item[curr]->Image->Type == sftTypeIDispatch) {
        pDataObject->SetData(_variant_t(m_vTree->Item[curr]->Image->GetPicture(), _variant_t((short)sftCFDIB)));
    } else {
        if (m_vTree->Item[curr]->Expanded != VARIANT_FALSE)
            pDataObject->SetData(_variant_t(m_vTree->Items->ItemImageExpanded->GetPicture(), _variant_t((short)sftCFDIB)));
        else if (m_vTree->Item[curr]->DependentAllCount > 0)
            pDataObject->SetData(_variant_t(m_vTree->Items->ItemImageExpandable->GetPicture(), _variant_t((short)sftCFDIB)));

See Also DataObject Object | Object Hierarchy


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