Export (0) Print
Expand All

DataObject.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 Public Overridable Function GetDataPresent(String) As Boolean Implements IDataObject.GetDataPresent
[C#] public virtual bool GetDataPresent(string);
[C++] public: virtual bool GetDataPresent(String*);
[JScript] public 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 Public Overridable Function GetDataPresent(Type) As Boolean Implements IDataObject.GetDataPresent
[C#] public virtual bool GetDataPresent(Type);
[C++] public: virtual bool GetDataPresent(Type*);
[JScript] public function GetDataPresent(Type) : Boolean;

Determines whether data stored in this instance is associated with the specified format, using an automatic conversion parameter to determine whether to convert the data to the format.

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

Example

[Visual Basic, C#, C++] The following example determines whether data currently stored in the DataObject is associated with a specified format. First, a new instance is initialized with a string, specifying its format as text.

[Visual Basic, C#, C++] Then the DataObject is queried for data associated with the text format, specifying the autoConvert parameter as false. The result of this query is printed in a text box.

[Visual Basic, C#, C++] Then the DataObject is queried for data associated with string format, specifying the autoConvert parameter as true. The results are printed in the text box. This code assumes textBox1 has been created.

[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 GetIfPresent3()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
    
    ' Prints the string in a text box with autoconvert = false.
    If myDataObject.GetDataPresent("System.String", False) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not convert data to specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text &= "With autoconvert = true, you can convert text to string format. " & _
                    "String is: " & myDataObject.GetData("System.String", True).ToString()
End Sub 'GetIfPresent3

[C#] 
private void GetIfPresent3() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "Another string");
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetDataPresent("System.String", false)) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
       textBox1.Text = "Could not convert data to specified format" + '\n';
 
    // Prints the string in a text box with autoconvert = true.
    textBox1.Text += "With autoconvert = true, you can convert text to string format. " +
       "String is: " + myDataObject.GetData("System.String", true).ToString();
 }
 

[C++] 
private:
void GetIfPresent3() {
    // Creates a new data object using a string and the text format.
    DataObject* myDataObject = new DataObject(DataFormats::Text, S"Another string");
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject->GetDataPresent(S"System.String", false)) {
       // 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 convert data to specified format\n";
 
    // Prints the string in a text box with autoconvert = true.
    textBox1->Text = String::Format( S"{0}With autoconvert = true, you can convert text to string format. String is: {1}",
       textBox1->Text, myDataObject->GetData(S"System.String",true) );
 }
 

[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

Show:
© 2014 Microsoft