Export (0) Print
Expand All

IDataObject.SetData Method (Object)

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

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

void SetData(
	Object data
)

Parameters

data
Type: System.Object
The data to store.

The format is derived from the data class.

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). Then it checks whether the specified data is stored in the data object, and displays the result in a message box. The example assumes that you have created a Form named Form1.


private void SetData1() 
{
    // Creates a component to store in the data object.
    Component myComponent = new Component();

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

    // Adds the component to the data object.
    myDataObject.SetData(myComponent);

    // Checks whether data of the specified type is in the data object.
    Type myType = myComponent.GetType();
    string myMessageText;
    if(myDataObject.GetDataPresent(myType))
         myMessageText = "Data of type " + myType.Name + 
            " is present in the data object";
    else
        myMessageText = "Data of type " + myType.Name +
            " is not present in the data object";

    // Displays the result in a message box.
    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.

Community Additions

ADD
Show:
© 2014 Microsoft