DataObject.GetDataPresent Method (Type)


Determines whether data stored in this DataObject is associated with, or can be converted to, the specified format.

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

public virtual bool GetDataPresent(
	Type format


Type: System.Type

A Type representing the format to check for.

Return Value

Type: System.Boolean

true if data stored in this DataObject is associated with, or can be converted to, the specified format; otherwise, false.

Call this method to determine whether a format exists before calling GetData. Call GetFormats for the formats that are available in this DataObject.


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.


If no data can be retrieved, no exception will be thrown. Instead, false will be returned.

The following code example determines whether data of the specified type exists in a DataObject, or whether the data can be converted to the specified type. The result is displayed in a text box. The code requires that textBox1 has been created.

private void GetIfPresent2() {
    // 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();

    // Determines if the DataObject has data of the Type format.
    textBox1.Text = "Is the specified data type available in the " +
       "DataObject? " + myDataObject.GetDataPresent(myType).ToString() + '\n';

    // Retrieves the data using its type format, and displays the type.
    Object myObject = myDataObject.GetData(myType);
    textBox1.Text += "The data type stored in the DataObject is: " +

.NET Framework
Available since 1.1
Return to top