IDataObject::SetData Method (Type^, Object^)
Stores the specified data and its associated class type in this instance.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- format
-
Type:
System::Type^
A Type representing the format associated with the data. See DataFormats for predefined formats.
- data
-
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 = gcnew Component; // Gets the type of the component. Type^ myType = myComponent->GetType(); // Creates a data object. DataObject^ myDataObject = gcnew 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; if ( myDataObject->GetDataPresent( myType ) ) { myMessageText = "Data of type " + myType->Name + " is stored in the data object"; } else { myMessageText = "No data of type " + myType->Name + " is stored in the data object"; } // Displays the result. MessageBox::Show( myMessageText, "The Test Result" ); }
Available since 1.1