Compartir a través de


Cómo: Mostrar los formatos de datos en un objeto de datos

Actualización: noviembre 2007

En los ejemplos siguientes se muestra cómo utilizar las sobrecargas del método GetFormats para obtener una matriz de cadenas que representan cada formato de datos que está disponible en un objeto de datos.

Ejemplo

Descripción

En el ejemplo de código siguiente se utiliza la sobrecarga de GetFormats para obtener una matriz de cadenas que representan todos los formatos de datos disponibles en un objeto de datos (tanto nativos como autoconvertibles).

Código

DataObject dataObject = new DataObject("Some string data to store...");

// Get an array of strings, each string denoting a data format
// that is available in the data object.  This overload of GetDataFormats
// returns all available data formats, native and auto-convertible.
string[] dataFormats = dataObject.GetFormats();

// Get the number of data formats present in the data object, including both
// auto-convertible and native data formats.
int numberOfDataFormats = dataFormats.Length;

// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
    if (dataFormat == DataFormats.Text)
    {
        // Take some action if/when data in the Text data format is found.
        break;
    }
    else if(dataFormat == DataFormats.StringFormat)
    {
        // Take some action if/when data in the string data format is found.
        break;
    }
}

Ejemplo

Descripción

En el ejemplo de código siguiente se utiliza la sobrecarga de GetFormats para obtener una matriz de cadenas que representan únicamente los formatos de datos disponibles en un objeto de datos (se filtran los formatos de datos autoconvertibles).

Código

DataObject dataObject = new DataObject("Some string data to store...");

// Get an array of strings, each string denoting a data format
// that is available in the data object.  This overload of GetDataFormats
// accepts a Boolean parameter inidcating whether to include auto-convertible
// data formats, or only return native data formats.
string[] dataFormats = dataObject.GetFormats(false /* Include auto-convertible? */);

// Get the number of native data formats present in the data object.
int numberOfDataFormats = dataFormats.Length;

// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
    if (dataFormat == DataFormats.Text)
    {
        // Take some action if/when data in the Text data format is found.
        break;
    }
}

Vea también

Conceptos

Información general sobre la función de arrastrar y colocar

Referencia

IDataObject

Otros recursos

Ejemplos Drag and Drop