This documentation is archived and is not being maintained.

IDataObject.GetData Method

Retrieves the data associated with the specified data format.

Overload List

Retrieves the data associated with the specified data format.

[Visual Basic] Overloads Function GetData(String) As Object
[C#] object GetData(string);
[C++] Object* GetData(String*);
[JScript] function GetData(String) : Object;

Retrieves the data associated with the specified class type format.

[Visual Basic] Overloads Function GetData(Type) As Object
[C#] object GetData(Type);
[C++] Object* GetData(Type*);
[JScript] function GetData(Type) : Object;

Retrieves the data associated with the specified data format, using a Boolean to determine whether to convert the data to the format.

[Visual Basic] Overloads Function GetData(String, Boolean) As Object
[C#] object GetData(string, bool);
[C++] Object* GetData(String*, bool);
[JScript] function GetData(String, Boolean) : Object;

Example

[Visual Basic, C#, C++] This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetData method. The example retrieves the data stored in a DataObject, using the autoConvert parameter to specify whether or not to convert the data format. First, myDataObject is created with text data. Then the example tries twice to retrieve the data. In the first trial, it specifies its format as a string and sets the autoConvert parameter to false. This trial fails, and the result is displayed in a message box labeled "Message #1." In the second trial, the example retrieves the same data with the autoConvert parameter set to true. This trial succeeds, and the result is displayed in a message box labeled "Message #2." The example assumes that you have created a Form named Form1.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetData. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub GetData3()
    ' Creates a new data object using a text string.
    Dim myString As String = "Hello World!"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Displays the string with autoConvert equal to false.
    If Not (myDataObject.GetData("System.String", False) Is Nothing) Then
        ' Displays the string in a message box.
        MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1")
        ' Displays a not found message in a message box.
    Else
        MessageBox.Show("Could not find data of the specified format.", "Message #1")
    End If

    ' Displays the string in a text box with autoConvert equal to true.
    Dim myData As String = "The data is " + myDataObject.GetData("System.String", True).ToString()
    MessageBox.Show(myData, "Message #2")
End Sub 'GetData3

[C#] 
private void GetData3() 
{
    // Creates a new data object using a text string.
    string myString = "Hello World!";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);
 
    // Displays the string with autoConvert equal to false.
    if (myDataObject.GetData("System.String", false) != null) 
    {
        // Displays the string in a message box.
        MessageBox.Show(myDataObject.GetData("System.String", false).ToString() + ".", "Message #1");
    } 
    else
        // Displays a not found message in a message box.
        MessageBox.Show("Could not find data of the specified format.", "Message #1");
 
    // Displays the string in a text box with autoConvert equal to true.
    string myData = "The data is " + myDataObject.GetData("System.String", true).ToString() +".";
    MessageBox.Show(myData,"Message #2");
}

[C++] 
private:
    void GetData3() {
        // Creates a new data object using a text string.
        String* myString = S"Hello World!";
        DataObject* myDataObject = 
            new DataObject(DataFormats::Text, myString);

        // Displays the string with autoConvert equal to false.
        if (myDataObject->GetData(S"System::String", false) != 0) {
            // Displays the string in a message box.
            MessageBox::Show(String::Concat(
                myDataObject->GetData(S"System::String", false), 
                S"."), S"Message #1");
        } else
            // Displays a not found message in a message box.
            MessageBox::Show(
            S"Could not find data of the specified format.", 
            S"Message #1");

        // Displays the string in a text box with autoConvert equal to true.
        String* myData = String::Concat(S"The data is ", 
            myDataObject->GetData(S"System::String", true), S".");
        MessageBox::Show(myData, S"Message #2");
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IDataObject Interface | IDataObject Members | System.Windows.Forms Namespace

Show: