This documentation is archived and is not being maintained.

IDataObject.GetDataPresent Method

Determines whether data stored in this instance is associated with the specified format.

Overload List

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

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

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

[Visual Basic] Overloads Function GetDataPresent(Type) As Boolean
[C#] bool GetDataPresent(Type);
[C++] bool GetDataPresent(Type*);
[JScript] function GetDataPresent(Type) : Boolean;

Determines whether data stored in this instance is associated with the specified format, using a Boolean value to determine whether to convert the data to the format.

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

Example

[Visual Basic, C#, C++] This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetDataPresent method. First, it creates a data object (myDataObject) using a string and the Text format. Then it queries the object for data associated with the Text format, with the autoConvert parameter set to false. This trial fails, and the result is displayed in a message box labeled "Message #1." In the second trial, it sets the autoConvert parameter 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 GetDataPresent. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub GetDataPresent3()
    ' Creates a new data object using a string and the Text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "My String")

    ' Checks whether the string can be displayed with autoConvert equal to false.
    If myDataObject.GetDataPresent("System.String", False) Then
        MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1")
    Else
        MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1")
    End If
    ' Displays the string with autoConvert equal to true.
    MessageBox.Show(("Now that autoConvert is true, you can convert " + myDataObject.GetData("System.String", _
         True).ToString() + " to string format."), "Message #2")

End Sub 'GetDataPresent3

[C#] 
private void GetDataPresent3() 
{
    // Creates a new data object using a string and the Text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "My String");
 
    // Checks whether the string can be displayed with autoConvert equal to false.
    if(myDataObject.GetDataPresent("System.String", false)) 
        MessageBox.Show(myDataObject.GetData("System.String", false).ToString(), "Message #1");
    else
        MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1");
 
    // Displays the string with autoConvert equal to true.
    MessageBox.Show("Now that autoConvert is true, you can convert " + 
        myDataObject.GetData("System.String", true).ToString() + " to string format.","Message #2");
}

[C++] 
private:
    void GetDataPresent3() {
        // Creates a new data object using a string and the Text format.
        DataObject* myDataObject = new DataObject(DataFormats::Text, S"My String");

        // Checks whether the string can be displayed with autoConvert equal to false.
        if (myDataObject->GetDataPresent(S"System::String", false))
            MessageBox::Show(
            myDataObject->GetData(S"System::String", false)->ToString(), 
            S"Message #1");
        else
            MessageBox::Show(
            S"Cannot convert data to the specified format with autoConvert set to false.", 
            S"Message #1");

        // Displays the string with autoConvert equal to true.
        MessageBox::Show(String::Concat(S"Now that autoConvert is true, you can convert ", 
            myDataObject->GetData(S"System::String", true), 
            S" to string format."), 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: