This documentation is archived and is not being maintained.

IDataObject.SetData Method

Stores the specified data and its associated format in this instance.

Overload List

Stores the specified data in this instance, using the class of the data for the format.

[Visual Basic] Overloads Sub SetData(Object)
[C#] void SetData(object);
[C++] void SetData(Object*);
[JScript] function SetData(Object);

Stores the specified data and its associated format in this instance.

[Visual Basic] Overloads Sub SetData(String, Object)
[C#] void SetData(string, object);
[C++] void SetData(String*, Object*);
[JScript] function SetData(String, Object);

Stores the specified data and its associated class type in this instance.

[Visual Basic] Overloads Sub SetData(Type, Object)
[C#] void SetData(Type, object);
[C++] void SetData(Type*, Object*);
[JScript] function SetData(Type, Object);

Stores the specified data and its associated format in this instance, using a Boolean value to specify whether the data can be converted to another format.

[Visual Basic] Overloads Sub SetData(String, Boolean, Object)
[C#] void SetData(string, bool, object);
[C++] void SetData(String*, bool, Object*);
[JScript] function SetData(String, Boolean, Object);

Example

[Visual Basic, C#, C++] This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the SetData method. First, it creates a data object (myDataObject) and stores a UnicodeText string in it, with the autoConvert parameter set to false. Then it retrieves the format(s) associated with the data stored in the object and displays the result in a message box. The only format associated with the data is the UnicodeText format. This example assumes that you have created a Form named Form1.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of SetData. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub SetData4()
    ' Creates a new data object.
    Dim myDataObject As New DataObject()

    ' Adds UnicodeText string to the object, and set the autoConvert
    ' parameter to false.
    myDataObject.SetData(DataFormats.UnicodeText, False, "My text string")

    ' Gets the data format(s) in the data object.
    Dim arrayOfFormats As [String]() = myDataObject.GetFormats()

    ' Stores the results in a string.
    Dim theResult As String = "The format(s) associated with the data are:" + _
            ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        theResult += arrayOfFormats(i) + ControlChars.Cr
    Next i
    ' Show the results in a message box. 
    MessageBox.Show(theResult)
End Sub 'SetData4 

[C#] 
private void SetData4() 
{
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds UnicodeText string to the object, and set the autoConvert 
    // parameter to false.
    myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");
 
    // Gets the data format(s) in the data object.
    String[] arrayOfFormats = myDataObject.GetFormats();
 
    // Stores the results in a string.
    string theResult = "The format(s) associated with the data are:" + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
        theResult += arrayOfFormats[i] + '\n';
    
    // Show the results in a message box. 
    MessageBox.Show(theResult);

}

[C++] 
private:
    void SetData4() {
        // Creates a new data object.
        DataObject* myDataObject = new DataObject();

        // Adds UnicodeText string to the object, and set the autoConvert
        // parameter to false.
        myDataObject->SetData(DataFormats::UnicodeText, false, S"My text String*");

        // Gets the data format(s) in the data object.
        String*  arrayOfFormats[] = myDataObject->GetFormats();

        // Stores the results in a string.
        String* theResult = S"The format(s) associated with the data are: \n";
        for (int i=0; i<arrayOfFormats->Length; i++)
            theResult = String::Concat(theResult, 
                arrayOfFormats->Item[i], S" \n");

        // Show the results in a message box.
        MessageBox::Show(theResult);

    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IDataObject Interface | IDataObject Members | System.Windows.Forms Namespace

Show: