Export (0) Print
Expand All

DataObject.GetData Method (String)

Returns the data associated with the specified data format.

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

Public Overridable Function GetData ( _
	format As String _
) As Object


Type: System.String

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 Nothing.



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 Nothing.

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.


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.

When format is Html, this method returns a UTF-8 encoded string in applications that target .NET 4.5 or higher, and an ANSI encoded string in applications that target .NET 4.0 or lower.

The following code example retrieves the data stored in a DataObject. First, a new DataObject is created with text data. Then, the data is retrieved, specifying its format as a string, and displayed in a text box.

This code requires that textBox1 has been created.

Private Sub AddMyData3()
    ' Creates a component to store in the data object. 
    Dim myComponent As New Component()

    ' Creates a new data object. 
    Dim myDataObject As New DataObject()

    ' Adds the component to the DataObject.

    ' Prints whether data of the specified type is in the DataObject. 
    Dim myType As Type = myComponent.GetType()
    If myDataObject.GetDataPresent(myType) Then
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is present in the DataObject" 
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is not present in the DataObject" 
    End If 
End Sub 'AddMyData3

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft