Export (0) Print
Expand All

DataObject.GetData Method (Type)

Returns the data associated with the specified class type format.

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

public virtual Object GetData(
	Type format
)

Parameters

format
Type: System.Type

A Type representing the format of the data to retrieve.

Return Value

Type: System.Object
The data associated with the specified format, or null.

Implements

IDataObject.GetData(Type)

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, or if the data was stored with automatic conversion set to false, 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 DataObject.

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.

The following code example retrieves the data stored in a DataObject. First, a new DataObject is created with a component. Then, the data is retrieved, specifying its type. The type of the retrieved data is displayed in a text box.

This code requires that textBox1 has been created.

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

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

    // Creates a type 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 != null)
       textBox1.Text = "The data type stored in the DataObject is: " +
       myObject.GetType().Name;
    else
       textBox1.Text = "Data of the specified type was not stored " +
       "in the DataObject.";
 }
 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft