Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataObject.GetData Method

Returns the data associated with the specified data format.

Overload List

Returns the data associated with the specified data format.

[Visual Basic] Overloads Public Overridable Function GetData(String) As Object Implements IDataObject.GetData
[C#] public virtual object GetData(string);
[C++] public: virtual Object* GetData(String*);
[JScript] public function GetData(String) : Object;

Returns the data associated with the specified class type format.

[Visual Basic] Overloads Public Overridable Function GetData(Type) As Object Implements IDataObject.GetData
[C#] public virtual object GetData(Type);
[C++] public: virtual Object* GetData(Type*);
[JScript] public function GetData(Type) : Object;

Returns the data associated with the specified data format, using an automated conversion parameter to determine whether to convert the data to the format.

[Visual Basic] Overloads Public Overridable Function GetData(String, Boolean) As Object Implements IDataObject.GetData
[C#] public virtual object GetData(string, bool);
[C++] public: virtual Object* GetData(String*, bool);
[JScript] public function GetData(String, Boolean) : Object;

Example

[Visual Basic, C#, C++] The following example retrieves the data stored in a DataObject, using the autoConvert parameter to specify whether to convert the data format.

[Visual Basic, C#, C++] First, a new DataObject is created with text data. Then the example tries to retrieve the data, specifying its format as a string and no format conversion, that is, the autoConvert parameter is false. This operation fails because there is no string data in the DataObject.

[Visual Basic, C#, C++] Next, the example tries to retrieve the data again, with the autoConvert parameter set to true. This operation succeeds and the results are displayed in a MessageBox.

[Visual Basic, C#, C++] This code assumes textBox1 has been created.

[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 GetMyData3()
    ' Creates a new data object using a string and the text format.
    Dim myString As String = "My new text string"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)
    
    ' Prints the string in a text box with autoconvert = false.
    If Not (myDataObject.GetData("System.String", False) Is Nothing) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not find data of the specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text += myDataObject.GetData("System.String", True).ToString()
End Sub 'GetMyData3

[C#] 
private void GetMyData3() {
    // Creates a new data object using a string and the text format.
    string myString = "My new text string";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetData("System.String", false) != null) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
       textBox1.Text = "Could not find data of the specified format" + '\n';
 
    // Prints the string in a text box with autoconvert = true.
    textBox1.Text += myDataObject.GetData("System.String", true).ToString();
 }
 

[C++] 
private:
void GetMyData3() {
    // Creates a new data object using a string and the text format.
    String* myString = S"My new text string";
    DataObject* myDataObject = new DataObject(DataFormats::Text, myString);
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject->GetData(S"System.String", false) != 0) {
       // Prints the string in a text box.
       textBox1->Text = String::Concat( myDataObject->GetData(S"System.String",false), S"\n");
    } else
       textBox1->Text = S"Could not find data of the specified format\n";
 
    // Prints the string in a text box with autoconvert = true.
    textBox1->Text =
       String::Concat(textBox1->Text, myDataObject->GetData(S"System.String", true)->ToString());
 }
 

[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

DataObject Class | DataObject Members | System.Windows.Forms Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft