This documentation is archived and is not being maintained.

IDataObject.SetData Method (Type, Object)

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

void SetData(
	Type format,
	Object data


Type: System.Type
A Type representing the format associated with the data. See DataFormats for predefined formats.
Type: System.Object
The data to store.

If you do not know the format of the target application, you can store data in multiple formats using this method.

Data stored using this method can be converted to a compatible format when it is retrieved.

For an implementation of this method, see DataObject.SetData.

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the SetData method. First, it creates a component (myComponent) and stores it in a data object (myDataObject), using myType to specify the data format. Then it checks whether the data of the specified type is stored in the object, and displays the result in a message box. The example assumes that you have created a Form named Form1.

private void SetData3() 
    // Creates a component.
    Component myComponent = new Component();

    // Gets the type of the component.
    Type myType = myComponent.GetType();

    // Creates a data object.
    DataObject myDataObject = new DataObject();

    // Stores the component in the data object.
    myDataObject.SetData(myType, myComponent);

    // Checks whether data of the specified type is in the data object.
    string myMessageText;
        myMessageText = "Data of type " + myType.Name + 
            " is stored in the data object";
        myMessageText = "No data of type " + myType.Name +
            " is stored in the data object";

    // Displays the result.
    MessageBox.Show(myMessageText, "The Test Result");

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.