DataObject.GetData Método
Definición
Devuelve los datos asociados con el formato de datos especificado.Returns the data associated with the specified data format.
Sobrecargas
GetData(String, Boolean) |
Devuelve los datos asociados con el formato de datos especificado, utilizando un parámetro de conversión automatizada para determinar si se deben convertir los datos a dicho formato.Returns the data associated with the specified data format, using an automated conversion parameter to determine whether to convert the data to the format. |
GetData(String) |
Devuelve los datos asociados con el formato de datos especificado.Returns the data associated with the specified data format. |
GetData(Type) |
Devuelve los datos asociados con el formato de tipo de clase especificado.Returns the data associated with the specified class type format. |
GetData(String, Boolean)
Devuelve los datos asociados con el formato de datos especificado, utilizando un parámetro de conversión automatizada para determinar si se deben convertir los datos a dicho formato.Returns the data associated with the specified data format, using an automated conversion parameter to determine whether to convert the data to the format.
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.The format of the data to retrieve. Vea DataFormats para obtener los formatos predefinidos.See DataFormats for predefined formats.
- autoConvert
- Boolean
true
para convertir los datos al formato especificado; en cualquier otro caso, false
.true
to the convert data to the specified format; otherwise, false
.
Devoluciones
Datos asociados al formato especificado o null
.The data associated with the specified format, or null
.
Implementaciones
Ejemplos
En el ejemplo de código siguiente se recuperan los datos almacenados en un DataObject, utilizando el parámetro autoConvert
para especificar si se va a convertir el formato de datos.The following code example retrieves the data stored in a DataObject, using the autoConvert
parameter to specify whether to convert the data format.
En primer lugar, se crea un nuevo DataObject con datos de texto.First, a new DataObject is created with text data. A continuación, el ejemplo intenta recuperar los datos, especificando su formato como una cadena y sin conversión de formato, es decir, el parámetro autoConvert
es false
.Then the example tries to retrieve the data, specifying its format as a string and no format conversion, that is, the autoConvert
parameter is false
. Se produce un error en esta operación porque no hay datos de cadena en el DataObject.This operation fails because there is no string data in the DataObject.
A continuación, el ejemplo intenta recuperar los datos de nuevo, con el parámetro autoConvert
establecido en true
.Next, the example tries to retrieve the data again, with the autoConvert
parameter set to true
. Esta operación se realiza correctamente y los resultados se muestran en un MessageBox.This operation succeeds and the results are displayed in a MessageBox.
Este código requiere que se haya creado textBox1
.This code requires that textBox1
has been created.
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 parámetro autoConvert
es true
y este método no puede encontrar datos en el formato especificado, intenta convertir los datos al formato.If the autoConvert
parameter is true
and this method cannot find data in the specified format, it attempts to convert the data to the format. Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida en false
, este método devuelve null
.If the data cannot be converted to the specified format, or if the data was stored with the automatic conversion set to false
, this method returns null
.
Si el parámetro autoConvert
es false
, este método devuelve los datos en el formato especificado o null
si no se pueden encontrar datos en este formato.If the autoConvert
parameter is false
, this method returns data in the specified format, or null
if no data in this format can be found.
Para determinar si los datos están asociados o se pueden convertir a un formato, llame a GetDataPresent antes de llamar a GetData.To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Llame a GetFormats para obtener una lista de formatos válidos para los datos almacenados en esta DataObject.Call GetFormats for a list of valid formats for the data stored in this DataObject.
Nota
Los datos se pueden convertir a otro formato si se almacenaron especificando que se permite la conversión y si el formato solicitado es compatible con el formato almacenado.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. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.For example, data stored as Unicode can be converted to text.
Cuando se Htmlformat
, este método devuelve una cadena con codificación UTF-8 en aplicaciones destinadas a .NET 4,5 o superior, y una cadena codificada con ANSI en aplicaciones destinadas a .NET 4,0 o inferior.When format
is Html, this method returns a UTF-8 encoded string in applications that target .NET 4.5 or higher, and an ANSI encoded string in applications that target .NET 4.0 or lower.
Consulte también:
GetData(String)
Devuelve los datos asociados con el formato de datos especificado.Returns the data associated with the specified data format.
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.The format of the data to retrieve. Vea DataFormats para obtener los formatos predefinidos.See DataFormats for predefined formats.
Devoluciones
Datos asociados al formato especificado o null
.The data associated with the specified format, or null
.
Implementaciones
Ejemplos
En el ejemplo de código siguiente se recuperan los datos almacenados en un DataObject.The following code example retrieves the data stored in a DataObject. En primer lugar, se crea un nuevo DataObject con datos de texto.First, a new DataObject is created with text data. A continuación, se recuperan los datos, se especifica su formato como una cadena y se muestran en un cuadro de texto.Then, the data is retrieved, specifying its format as a string, and displayed in a text box.
Este código requiere que se haya creado textBox1
.This code requires that textBox1
has been created.
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 puede encontrar datos en el formato especificado, intenta convertir los datos al formato.If this method cannot find data in the specified format, it attempts to convert the data to the format. Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida en false
, este método devuelve null
.If the data cannot be converted to the specified format, or if the data was stored with automatic conversion set to false
, this method returns null
.
Para determinar si los datos están asociados o se pueden convertir a un formato, llame a GetDataPresent antes de llamar a GetData.To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Llame a GetFormats para obtener una lista de formatos válidos para los datos almacenados en esta DataObject.Call GetFormats for a list of valid formats for the data stored in this DataObject.
Nota
Los datos se pueden convertir a otro formato si se almacenaron especificando que se permite la conversión y si el formato solicitado es compatible con el formato almacenado.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. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.For example, data stored as Unicode can be converted to text.
Cuando se Htmlformat
, este método devuelve una cadena con codificación UTF-8 en aplicaciones destinadas a .NET 4,5 o superior, y una cadena codificada con ANSI en aplicaciones destinadas a .NET 4,0 o inferior.When format
is Html, this method returns a UTF-8 encoded string in applications that target .NET 4.5 or higher, and an ANSI encoded string in applications that target .NET 4.0 or lower.
Consulte también:
GetData(Type)
Devuelve los datos asociados con el formato de tipo de clase especificado.Returns the data associated with the specified class type format.
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
Type que representa el formato de los datos que se van a recuperar.A Type representing the format of the data to retrieve.
Devoluciones
Datos asociados al formato especificado o null
.The data associated with the specified format, or null
.
Implementaciones
Ejemplos
En el ejemplo de código siguiente se recuperan los datos almacenados en un DataObject.The following code example retrieves the data stored in a DataObject. En primer lugar, se crea un nuevo DataObject con un componente.First, a new DataObject is created with a component. A continuación, se recuperan los datos y se especifica su tipo.Then, the data is retrieved, specifying its type. El tipo de los datos recuperados se muestra en un cuadro de texto.The type of the retrieved data is displayed in a text box.
Este código requiere que se haya creado textBox1
.This code requires that textBox1
has been created.
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 puede encontrar datos en el formato especificado, intenta convertir los datos al formato.If this method cannot find data in the specified format, it attempts to convert the data to the format. Si los datos no se pueden convertir al formato especificado o si los datos se almacenaron con la conversión automática establecida en false
, este método devuelve null
.If the data cannot be converted to the specified format, or if the data was stored with automatic conversion set to false
, this method returns null
.
Para determinar si los datos están asociados o se pueden convertir a un formato, llame a GetDataPresent antes de llamar a GetData.To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Llame a GetFormats para obtener una lista de formatos válidos para los datos almacenados en esta DataObject.Call GetFormats for a list of valid formats for the data stored in this DataObject.
Nota
Los datos se pueden convertir a otro formato si se almacenaron especificando que se permite la conversión y si el formato solicitado es compatible con el formato almacenado.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. Por ejemplo, los datos almacenados como Unicode se pueden convertir en texto.For example, data stored as Unicode can be converted to text.