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 virtual Object GetData (
	string format
)
public Object GetData (
	String format
)
public function GetData (
	format : String
) : Object
Not applicable.

Parameters

format

The format of the data to retrieve. See DataFormats for predefined formats.

Return Value

The data associated with the specified format, or a null reference (Nothing in Visual Basic).

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 a null reference (Nothing in Visual Basic).

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 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 void AddMyData3() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds the component to the DataObject.
    myDataObject.SetData(myComponent);
 
    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();
    if(myDataObject.GetDataPresent(myType))
       textBox1.Text = "Data of type " + myType.ToString() + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.ToString() +
       " is not present in the DataObject";
 }

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

    // Creates a new data object.
    DataObject myDataObject = new DataObject();

    // Adds the component to the DataObject.
    myDataObject.SetData(myComponent);

    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();

    if (myDataObject.GetDataPresent(myType)) {
        textBox1.set_Text("Data of type " + myType.ToString() 
            + " is present in the DataObject");
    }
    else {
        textBox1.set_Text("Data of type " + myType.ToString() 
            + " is not present in the DataObject");
    }
} //AddMyData3

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show: