Bewerken

Delen via


DataObject.GetDataPresent Method

Definition

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

Overloads

GetDataPresent(String)

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

GetDataPresent(Type)

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

GetDataPresent(String, Boolean)

Determines whether this DataObject contains data in the specified format or, optionally, contains data that can be converted to the specified format.

GetDataPresent(String)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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

public:
 virtual bool GetDataPresent(System::String ^ format);
public virtual bool GetDataPresent (string format);
abstract member GetDataPresent : string -> bool
override this.GetDataPresent : string -> bool
Public Overridable Function GetDataPresent (format As String) As Boolean

Parameters

format
String

The format to check for. See DataFormats for predefined formats.

Returns

true if data stored in this DataObject is associated with, or can be converted to, the specified format; otherwise, false.

Implements

Examples

The following code example determines whether data currently stored in this DataObject is associated with, or can be converted to, a specified format. A new DataObject is initialized with a string and its associated format specified as text.

Then the examples prints whether text data exists in the DataObject. This code requires that textBox1 has been created.

Remarks

Call this method to determine whether a format exists before calling GetData. Call GetFormats for the formats that are available in this DataObject.

Note

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.

Note

If no data can be retrieved, no exception will be thrown. Instead, false will be returned.

See also

Applies to

GetDataPresent(Type)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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

public:
 virtual bool GetDataPresent(Type ^ format);
public virtual bool GetDataPresent (Type format);
abstract member GetDataPresent : Type -> bool
override this.GetDataPresent : Type -> bool
Public Overridable Function GetDataPresent (format As Type) As Boolean

Parameters

format
Type

A Type representing the format to check for.

Returns

true if data stored in this DataObject is associated with, or can be converted to, the specified format; otherwise, false.

Implements

Examples

The following code example determines whether data of the specified type exists in a DataObject, or whether the data can be converted to the specified type. The result is displayed in a text box. The code requires that textBox1 has been created.

private:
   void GetIfPresent2()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject( myComponent );
      
      // Creates a type to store the type of data.
      Type^ myType = myComponent->GetType();
      
      // Determines if the DataObject has data of the Type format.
      textBox1->Text = String::Concat( "Is the specified data type available ",
         "in the DataObject? ", myDataObject->GetDataPresent( myType ), "\n" );
      
      // Retrieves the data using its type format, and displays the type.
      Object^ myObject = myDataObject->GetData( myType );
      textBox1->Text = String::Concat( textBox1->Text, "The data type stored ",
         "in the DataObject is: ", myObject->GetType()->Name );
   }
private void GetIfPresent2() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object and assigns it the component.
    DataObject myDataObject = new DataObject(myComponent);
 
    // Creates a type to store the type of data.
    Type myType = myComponent.GetType();
 
    // Determines if the DataObject has data of the Type format.
    textBox1.Text = "Is the specified data type available in the " +
       "DataObject? " + myDataObject.GetDataPresent(myType).ToString() + '\n';
 
    // Retrieves the data using its type format, and displays the type.
    Object myObject = myDataObject.GetData(myType);
    textBox1.Text += "The data type stored in the DataObject is: " +
       myObject.GetType().Name;
 }
Private Sub GetIfPresent2()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object and assigns it the component.
    Dim myDataObject As New DataObject(myComponent)
    
    ' Creates a type to store the type of data.
    Dim myType As Type = myComponent.GetType()
    
    ' Determines if the DataObject has data of the Type format.
    textBox1.Text = "Is the specified data type available in the " & "DataObject? " & _
        myDataObject.GetDataPresent(myType).ToString() & ControlChars.Cr
    
    ' Retrieves the data using its type format, and displays the type.
    Dim myObject As Object = myDataObject.GetData(myType)
    textBox1.Text += "The data type stored in the DataObject is: " + myObject.GetType().Name
End Sub

Remarks

Call this method to determine whether a format exists before calling GetData. Call GetFormats for the formats that are available in this DataObject.

Note

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.

Note

If no data can be retrieved, no exception will be thrown. Instead, false will be returned.

See also

Applies to

GetDataPresent(String, Boolean)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Determines whether this DataObject contains data in the specified format or, optionally, contains data that can be converted to the specified format.

public:
 virtual bool GetDataPresent(System::String ^ format, bool autoConvert);
public virtual bool GetDataPresent (string format, bool autoConvert);
abstract member GetDataPresent : string * bool -> bool
override this.GetDataPresent : string * bool -> bool
Public Overridable Function GetDataPresent (format As String, autoConvert As Boolean) As Boolean

Parameters

format
String

The format to check for. See DataFormats for predefined formats.

autoConvert
Boolean

true to determine whether data stored in this DataObject can be converted to the specified format; false to check whether the data is in the specified format.

Returns

true if the data is in, or can be converted to, the specified format; otherwise, false.

Implements

Examples

The following code example determines whether data currently stored in the DataObject is associated with a specified format. First, a new DataObject is initialized with a string, specifying its format as text.

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.

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 requires that textBox1 has been created.

private:
   void GetIfPresent3()
   {
      // Creates a new data object using a string and the text format.
      DataObject^ myDataObject = gcnew 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 = String::Concat(
            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 = String::Concat( textBox1->Text,
         "With autoconvert = true, you can convert text to string format. String is: ",
         myDataObject->GetData( "System.String", true )->ToString() );
   }
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();
 }
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

Remarks

Call this method to determine whether a format exists before calling GetData. Call GetFormats for the formats that are available in this DataObject.

This method returns true when:

  • The autoConvert parameter is true and the data is in a format that can be converted to the appropriate format.

  • The autoConvert parameter is false and the data is in the appropriate format.

This method returns false when:

  • The autoConvert parameter is true and this method cannot find data in the specified format, and it cannot convert data to the specified format, or the data was stored with automatic conversion set to false.

  • The autoConvert parameter is false and data does not exist in this DataObject in the specified format.

Note

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.

Note

If no data can be retrieved, no exception will be thrown. Instead, false will be returned.

See also

Applies to