Share via


DataObject.GetDataPresent Método

Definición

Determina si los datos almacenados en este objeto DataObject están asociados al formato especificado.

Sobrecargas

GetDataPresent(String)

Determina si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo.

GetDataPresent(Type)

Determina si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo.

GetDataPresent(String, Boolean)

Determina si este objeto DataObject contiene datos con el formato especificado u, opcionalmente, si contiene datos que se pueden convertir al formato especificado.

GetDataPresent(String)

Determina si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo.

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

Parámetros

format
String

Formato que se comprueba. Vea DataFormats para obtener los formatos predefinidos.

Devoluciones

Boolean

true si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo; de lo contrario, false.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se determina si los datos almacenados actualmente en este DataObject objeto están asociados o se pueden convertir en un formato especificado. Un nuevo DataObject se inicializa con una cadena y su formato asociado especificado como texto.

A continuación, los ejemplos imprimen si existen datos de texto en .DataObject Este código requiere que textBox1 se haya creado.

Comentarios

Llame a este método para determinar si existe un formato antes de llamar a GetData. Llame a GetFormats para los formatos que están disponibles en este DataObject.

Nota

Los datos se pueden convertir a otro formato si se almacenó especificando esa conversión y si el formato solicitado es compatible con el formato almacenado. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.

Nota

Si no se pueden recuperar datos, no se producirá ninguna excepción. En su lugar, false se devolverá.

Consulte también

Se aplica a

GetDataPresent(Type)

Determina si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo.

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

Parámetros

format
Type

Type que representa el formato que se va a comprobar.

Devoluciones

Boolean

true si los datos almacenados en este objeto DataObject están asociados al formato especificado o se pueden convertir al mismo; de lo contrario, false.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se determina si existen datos del tipo especificado en o DataObjectsi los datos se pueden convertir al tipo especificado. El resultado se muestra en un cuadro de texto. El código requiere que textBox1 se haya creado.

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

Comentarios

Llame a este método para determinar si existe un formato antes de llamar a GetData. Llame a GetFormats para los formatos que están disponibles en este DataObject.

Nota

Los datos se pueden convertir a otro formato si se almacenó especificando esa conversión y si el formato solicitado es compatible con el formato almacenado. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.

Nota

Si no se pueden recuperar datos, no se producirá ninguna excepción. En su lugar, false se devolverá.

Consulte también

Se aplica a

GetDataPresent(String, Boolean)

Determina si este objeto DataObject contiene datos con el formato especificado u, opcionalmente, si contiene datos que se pueden convertir al formato especificado.

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

Parámetros

format
String

Formato que se comprueba. Vea DataFormats para obtener los formatos predefinidos.

autoConvert
Boolean

true para determinar si los datos almacenados en este objeto DataObject se pueden convertir al formato especificado; false para comprobar si los datos tienen el formato especificado.

Devoluciones

Boolean

Es true si los datos tienen el formato especificado o se pueden convertir en él; de lo contrario, es false.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se determina si los datos almacenados actualmente en está DataObject asociado a un formato especificado. En primer lugar, se inicializa un nuevo DataObject con una cadena, especificando su formato como texto.

A continuación, se consulta para DataObject los datos asociados al formato de texto, especificando el autoConvert parámetro como false. El resultado de esta consulta se imprime en un cuadro de texto.

A continuación, se consulta para DataObject los datos asociados con el formato de cadena, especificando el autoConvert parámetro como true. Los resultados se imprimen en el cuadro de texto. Este código requiere que textBox1 se haya creado.

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

Comentarios

Llame a este método para determinar si existe un formato antes de llamar a GetData. Llame a GetFormats para los formatos que están disponibles en este DataObject.

Este método devuelve true cuando:

  • El autoConvert parámetro es true y los datos están en un formato que se puede convertir al formato adecuado.

  • El autoConvert parámetro es false y los datos tienen el formato adecuado.

Este método devuelve false cuando:

  • El autoConvert parámetro es true y este método no puede encontrar datos en el formato especificado y no puede convertir los datos en el formato especificado o los datos se almacenaron con la conversión automática establecida falseen .

  • El autoConvert parámetro es false y los datos no existen en este DataObject formato en el formato especificado.

Nota

Los datos se pueden convertir a otro formato si se almacenó especificando esa conversión y si el formato solicitado es compatible con el formato almacenado. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.

Nota

Si no se pueden recuperar datos, no se producirá ninguna excepción. En su lugar, false se devolverá.

Consulte también

Se aplica a