DataObject.GetData Método

Definición

Devuelve los datos asociados al formato de datos especificado.

Sobrecargas

Nombre Description
GetData(String, Boolean)

Devuelve los datos asociados al formato de datos especificado, mediante un parámetro de conversión automatizado para determinar si se van a convertir los datos en el formato.

GetData(String)

Devuelve los datos asociados al formato de datos especificado.

GetData(Type)

Devuelve los datos asociados al formato de tipo de clase especificado.

GetData(String, Boolean)

Devuelve los datos asociados al formato de datos especificado, mediante un parámetro de conversión automatizado para determinar si se van a convertir los datos en el formato.

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

Parámetros

format
String

Formato de los datos que se van a recuperar. Consulte DataFormats para conocer los formatos predefinidos.

autoConvert
Boolean

true a los datos de conversión al formato especificado; de lo contrario, false.

Devoluciones

Los datos asociados al formato especificado o null.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se recuperan los datos almacenados en , DataObjectmediante el autoConvert parámetro para especificar si se va a convertir el formato de datos.

En primer lugar, se crea un nuevo DataObject con datos de texto. A continuación, el ejemplo intenta recuperar los datos, especificando su formato como una cadena y sin conversión de formato, es decir, el autoConvert parámetro es false. Se produce un error en esta operación porque no hay datos de cadena en .DataObject

A continuación, el ejemplo intenta recuperar los datos de nuevo, con el autoConvert parámetro establecido trueen . Esta operación se realiza correctamente y los resultados se muestran en .MessageBox

Este código requiere que textBox1 se haya creado.

private:
   void GetMyData3()
   {
      // Creates a new data object using a string and the text format.
      String^ myString = "My new text string";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );
      
      // Prints the string in a text box with autoconvert = false.
      if ( myDataObject->GetData( "System.String", false ) != 0 )
      {
         // Prints the string in a text box.
         textBox1->Text = String::Concat(
            myDataObject->GetData( "System.String", false )->ToString(), "\n" );
      }
      else
      {
         textBox1->Text = "Could not find data of the specified format\n";
      }
      
      // Prints the string in a text box with autoconvert = true.
      textBox1->Text = String::Concat(
            textBox1->Text, myDataObject->GetData( "System.String", true )->ToString() );
   }
private void GetMyData3() {
    // Creates a new data object using a string and the text format.
    string myString = "My new text string";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetData("System.String", false) != null) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
        {
            textBox1.Text = "Could not find data of the specified format" + '\n';
        }

        // Prints the string in a text box with autoconvert = true.
        textBox1.Text += myDataObject.GetData("System.String", true).ToString();
 }
Private Sub GetMyData3()
    ' Creates a new data object using a string and the text format.
    Dim myString As String = "My new text string"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)
    
    ' Prints the string in a text box with autoconvert = false.
    If (myDataObject.GetData("System.String", False) IsNot Nothing) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not find data of the specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text += myDataObject.GetData("System.String", True).ToString()
End Sub

Comentarios

Si el autoConvert parámetro es true y este método no puede encontrar datos en el formato especificado, intenta convertir los datos al formato. Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida falseen , este método devuelve null.

Si el autoConvert parámetro es false, este método devuelve datos en el formato especificado o null si no se encuentra ningún dato en este formato.

Para determinar si los datos están asociados a , o se pueden convertir a , un formato, llame GetDataPresent a antes de llamar a GetData. Llame GetFormats a para obtener una lista de formatos válidos para los datos almacenados en este DataObject.

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.

Cuando format es Html, este método devuelve una cadena codificada UTF-8 en las aplicaciones que tienen como destino .NET 4.5 o superior, y una cadena codificada ANSI en las aplicaciones que tienen como destino .NET 4.0 o inferior.

Consulte también

Se aplica a

GetData(String)

Devuelve los datos asociados al formato de datos especificado.

public:
 virtual System::Object ^ GetData(System::String ^ format);
public virtual object GetData(string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Overridable Function GetData (format As String) As Object

Parámetros

format
String

Formato de los datos que se van a recuperar. Consulte DataFormats para conocer los formatos predefinidos.

Devoluciones

Los datos asociados al formato especificado o null.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se recuperan los datos almacenados en .DataObject En primer lugar, se crea un nuevo DataObject con datos de texto. A continuación, los datos se recuperan, especifican su formato como una cadena y se muestran en un cuadro de texto.

Este código requiere que textBox1 se haya creado.

private:
   void AddMyData3()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the DataObject.
      myDataObject->SetData( myComponent );
      
      // Prints whether data of the specified type is in the DataObject.
      Type^ myType = myComponent->GetType();
      if ( myDataObject->GetDataPresent( myType ) )
      {
         textBox1->Text = String::Concat( "Data of type ", myType,
            " is present in the DataObject" );
      }
      else
      {
         textBox1->Text = String::Concat( "Data of type ", myType,
            " is not present in the DataObject" );
      }
   }
private void AddMyData3() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds the component to the DataObject.
    myDataObject.SetData(myComponent);
 
    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();
    if(myDataObject.GetDataPresent(myType))
       textBox1.Text = "Data of type " + myType.ToString() + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.ToString() +
       " is not present in the DataObject";
 }
Private Sub AddMyData3()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object.
    Dim myDataObject As New DataObject()
    
    ' Adds the component to the DataObject.
    myDataObject.SetData(myComponent)
    
    ' Prints whether data of the specified type is in the DataObject.
    Dim myType As Type = myComponent.GetType()
    If myDataObject.GetDataPresent(myType) Then
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is present in the DataObject"
    Else
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is not present in the DataObject"
    End If
End Sub

Comentarios

Si este método no encuentra datos en el formato especificado, intenta convertir los datos al formato . Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida falseen , este método devuelve null.

Para determinar si los datos están asociados a , o se pueden convertir a , un formato, llame GetDataPresent a antes de llamar a GetData. Llame GetFormats a para obtener una lista de formatos válidos para los datos almacenados en este DataObject.

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.

Cuando format es Html, este método devuelve una cadena codificada UTF-8 en las aplicaciones que tienen como destino .NET 4.5 o superior, y una cadena codificada ANSI en las aplicaciones que tienen como destino .NET 4.0 o inferior.

Consulte también

Se aplica a

GetData(Type)

Devuelve los datos asociados al formato de tipo de clase especificado.

public:
 virtual System::Object ^ GetData(Type ^ format);
public virtual object GetData(Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
Public Overridable Function GetData (format As Type) As Object

Parámetros

format
Type

que Type representa el formato de los datos que se van a recuperar.

Devoluciones

Los datos asociados al formato especificado o null.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se recuperan los datos almacenados en .DataObject En primer lugar, se crea un nuevo DataObject con un componente. A continuación, se recuperan los datos y se especifica su tipo. El tipo de los datos recuperados se muestra en un cuadro de texto.

Este código requiere que textBox1 se haya creado.

private:
   void GetMyData()
   {
      // 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();
      
      // Retrieves the data using myType to represent its type.
      Object^ myObject = myDataObject->GetData( myType );
      if ( myObject != nullptr )
      {
         textBox1->Text = String::Format( "The data type stored in the DataObject is: {0}",
            myObject->GetType()->Name );
      }
      else
      {
         textBox1->Text = "Data of the specified type was not stored in the DataObject.";
      }
   }
private void GetMyData() {
    // 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();
 
    // Retrieves the data using myType to represent its type.
    Object myObject = myDataObject.GetData(myType);
    if(myObject != null)
       textBox1.Text = "The data type stored in the DataObject is: " +
       myObject.GetType().Name;
    else
       textBox1.Text = "Data of the specified type was not stored " +
       "in the DataObject.";
 }
Private Sub GetMyData()
    ' 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()
    
    ' Retrieves the data using myType to represent its type.
    Dim myObject As Object = myDataObject.GetData(myType)
    If (myObject IsNot Nothing) Then
        textBox1.Text = "The data type stored in the DataObject is: " & myObject.GetType().Name
    Else
        textBox1.Text = "Data of the specified type was not stored " & "in the DataObject."
    End If
End Sub

Comentarios

Si este método no encuentra datos en el formato especificado, intenta convertir los datos al formato . Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida falseen , este método devuelve null.

Para determinar si los datos están asociados a , o se pueden convertir a , un formato, llame GetDataPresent a antes de llamar a GetData. Llame GetFormats a para obtener una lista de formatos válidos para los datos almacenados en este DataObject.

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.

Consulte también

Se aplica a