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 = gcnew Component;

      // Creates a data object.
      DataObject^ myDataObject = gcnew 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
Available since 1.1
Return to top
Show: