IDataObject::GetData Method (Type^)

 

Retrieves the data associated with the specified class type format.

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

Object^ GetData(
	Type^ format
)

Parameters

format
Type: System::Type^

A Type representing the format of the data to retrieve. See DataFormats for predefined formats.

Return Value

Type: System::Object^

The data associated with the specified format, or null.

If this method cannot find data in the specified format, it attempts to convert the data to the format. If the data cannot be converted to the specified format, this method returns null.

To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Call GetFormats for a list of valid formats for the data stored in this instance.

System_CAPS_noteNote

Data can be converted to another format if it was stored specifying that conversion is allowed, and if the requested format is compatible with the stored format. For example, data stored as Unicode can be converted to text.

For an implementation of this method, see DataObject::GetData.

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetData method. The method is used to retrieve the data stored in myObject, which is associated with a specific type, myType. The type of the retrieved data is displayed in a message box. The example assumes that you have already created a Form named Form1.

private:
   void GetData2()
   {
      // Creates a component.
      Component^ myComponent = gcnew Component;

      // Creates a data object, and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject( myComponent );

      // Creates a type, myType, to store the type of data.
      Type^ myType = myComponent->GetType();

      // Retrieves the data using myType to represent its type.
      Object^ myObject = myDataObject->GetData( myType );
      if ( myObject != nullptr )
            MessageBox::Show( "The data type stored in the data object is " +
                  myObject->GetType()->Name + "." );
      else
            MessageBox::Show( "Data of the specified type was not stored in the data object." );
   }

.NET Framework
Available since 1.1
Return to top
Show: