IDataObject.GetDataPresent Método

Definición

Determina si los datos almacenados en esta instancia están asociados al formato especificado.

Sobrecargas

Nombre Description
GetDataPresent(String)

Determina si los datos almacenados en esta instancia están asociados o se pueden convertir al formato especificado.

GetDataPresent(Type)

Determina si los datos almacenados en esta instancia están asociados o se pueden convertir al formato especificado.

GetDataPresent(String, Boolean)

Determina si los datos almacenados en esta instancia están asociados con el formato especificado, utilizando un valor booleano para determinar si se van a convertir los datos al formato.

GetDataPresent(String)

Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs

Determina si los datos almacenados en esta instancia están asociados o se pueden convertir al formato especificado.

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

Parámetros

format
String

Formato para el que se va a comprobar. Consulte DataFormats para conocer los formatos predefinidos.

Devoluciones

true si los datos almacenados en esta instancia están asociados o se pueden convertir al formato especificado; de lo contrario false, es .

Ejemplos

En este ejemplo se usa la DataObject clase , que implementa IDataObject, para demostrar el uso del GetDataPresent método . En primer lugar, crea un objeto de datos mediante una cadena y el Text formato . A continuación, comprueba que los datos están presentes en el Text formato y muestra los resultados en un cuadro de mensaje. En el ejemplo se supone que ha creado un Form objeto denominado Form1.

private:
   void TestDataObject()
   {
      // Creates a new data object using a string and the Text format.
      String^ myString = "Hello World!";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );

      // Checks whether the data is present in the Text format and displays the result.
      if ( myDataObject->GetDataPresent( DataFormats::Text ) )
            MessageBox::Show( "The stored data is in the Text format.", "Test Result" );
      else
            MessageBox::Show( "The stored data is not in the Text format.", "Test Result" );
   }
       private void TestDataObject() 
       {
           // Creates a new data object using a string and the Text format.
           string myString = "Hello World!";
           DataObject myDataObject = new DataObject(DataFormats.Text, myString);

           // Checks whether the data is present in the Text format and displays the result.
           if (myDataObject.GetDataPresent(DataFormats.Text))
               MessageBox.Show("The stored data is in the Text format." , "Test Result");
           else
               MessageBox.Show("The stored data is not in the Text format.", "Test Result");
       }
Private Sub TestDataObject()
    ' Creates a new data object using a string and the Text format.
    Dim myString As New String("Hello World!")
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Checks whether the data is present in the Text format and displays the result.
    If (myDataObject.GetDataPresent(DataFormats.Text)) Then
        MessageBox.Show("The stored data is in the Text format.", "Test Result")
    Else
        MessageBox.Show("The stored data is not in the Text format.", "Test Result")
    End If
End Sub

Comentarios

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

Note

Los datos se pueden convertir a otro formato si se almacenó especificando que se permite la 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.

Para obtener una implementación de este método, vea DataObject.GetDataPresent.

Consulte también

Se aplica a

GetDataPresent(Type)

Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs

Determina si los datos almacenados en esta instancia están asociados o se pueden convertir al formato especificado.

public:
 bool GetDataPresent(Type ^ format);
public bool GetDataPresent(Type format);
abstract member GetDataPresent : Type -> bool
Public Function GetDataPresent (format As Type) As Boolean

Parámetros

format
Type

Type que representa el formato para el que se va a comprobar. Consulte DataFormats para conocer los formatos predefinidos.

Devoluciones

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

Ejemplos

En este ejemplo se usa la DataObject clase , que implementa IDataObject, para demostrar el uso del GetDataPresent método . En primer lugar, crea un componente (myComponent) y lo almacena en un objeto de datos (myDataObject). A continuación, comprueba si los datos especificados se almacenan en myDataObject. Si la prueba evalúa true, muestra el resultado en un cuadro de mensaje y muestra el tipo de datos en un cuadro de texto. En este ejemplo se da por supuesto que ya ha creado un objeto con nombre FormForm1 y un TextBox denominado textBox1.

private:
   void GetDataPresent2()
   {
      // 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();

      // Checks whether the specified data type exists in the object.
      if ( myDataObject->GetDataPresent( myType ) )
      {
         MessageBox::Show( "The specified data is stored in the data object." );

         // Displays the type of data.
         textBox1->Text = "The data type is " + myDataObject->GetData( myType )->GetType()->Name + ".";
      }
      else
            MessageBox::Show( "The specified data is not stored in the data object." );
   }
       private void GetDataPresent2() 
       {
           // 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();

           // Checks whether the specified data type exists in the object.
           if (myDataObject.GetDataPresent(myType))
           {
               MessageBox.Show("The specified data is stored in the data object.");
               // Displays the type of data.
               textBox1.Text = "The data type is " + myDataObject.GetData(myType).GetType().Name + ".";
           }
           else
           {
               MessageBox.Show("The specified data is not stored in the data object.");
           }
       }
Private Sub GetDataPresent2()
    ' Creates a component to store in the data object.
    Dim myComponent As New System.ComponentModel.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()

    ' Checks whether the specified data type exists in the object.
    If myDataObject.GetDataPresent(myType) Then
        MessageBox.Show("The specified data is stored in the data object.")
        ' Displays the type of data.
        TextBox1.Text = "The data type is " & myDataObject.GetData(myType).GetType().Name & "."
    Else
        MessageBox.Show("The specified data is not stored in the data object.")
    End If
End Sub

Comentarios

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

Note

Los datos se pueden convertir a otro formato si se almacenó especificando que se permite la 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.

Para obtener una implementación de este método, vea DataObject.GetDataPresent.

Consulte también

Se aplica a

GetDataPresent(String, Boolean)

Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs
Source:
IDataObject.cs

Determina si los datos almacenados en esta instancia están asociados con el formato especificado, utilizando un valor booleano para determinar si se van a convertir los datos al formato.

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

Parámetros

format
String

Formato para el que se va a comprobar. Consulte DataFormats para conocer los formatos predefinidos.

autoConvert
Boolean

true para determinar si los datos almacenados en esta instancia se pueden convertir al formato especificado; false para comprobar si los datos están en el formato especificado.

Devoluciones

true si los datos están en , o se pueden convertir a , el formato especificado; de lo contrario, false.

Ejemplos

En este ejemplo se usa la DataObject clase , que implementa IDataObject, para demostrar el uso del GetDataPresent método . En primer lugar, crea un objeto de datos (myDataObject) mediante una cadena y el Text formato . A continuación, consulta el objeto para los datos asociados al Text formato , con el autoConvert parámetro establecido falseen . Esta prueba produce un error y el resultado se muestra en un cuadro de mensaje con la etiqueta "Mensaje n.º 1". En la segunda prueba, establece el autoConvert parámetro trueen . Esta prueba se realiza correctamente y el resultado se muestra en un cuadro de mensaje con la etiqueta "Mensaje n.º 2". En el ejemplo se supone que ha creado un Form objeto denominado Form1.

private:
   void GetDataPresent3()
   {
      // Creates a new data object using a string and the Text format.
      DataObject^ myDataObject = gcnew 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 ) + " to string format.", "Message #2" );
   }
       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");
       }
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

Comentarios

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

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 establecido autoConverten false .

  • El autoConvert parámetro es falsey los datos no existen en esta instancia en el formato especificado.

Note

Los datos se pueden convertir a otro formato si se almacenó especificando que se permite la 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.

Para obtener una implementación de este método, vea DataObject.GetDataPresent.

Consulte también

Se aplica a