Export (0) Print
Expand All

DataObject.GetFormats Method (Boolean)

Returns a list of all formats that data stored in this DataObject is associated with or can be converted to, using an automatic conversion parameter to determine whether to retrieve only native data formats or all formats that the data can be converted to.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual string[] GetFormats (
	bool autoConvert
)
public String[] GetFormats (
	boolean autoConvert
)
public function GetFormats (
	autoConvert : boolean
) : String[]
Not applicable.

Parameters

autoConvert

true to retrieve all formats that data stored in this DataObject is associated with, or can be converted to; false to retrieve only native data formats.

Return Value

An array of type String, containing a list of all formats that are supported by the data stored in this object.

Call this method to get the supported data formats before calling GetData. See DataFormats for the predefined formats.

NoteNote:

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. For example, data stored as Unicode can be converted to text.

The following code example queries a DataObject for the formats associated with its data. The first query specifies the autoConvert parameter as false, so only the native format of the data is returned. The second query specifies the autoConvert parameter as true, so the list of formats includes the formats that the data can be converted to.

This code requires that textBox1 has been created.

private void GetAllFormats2() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, "Another string");
 
    // Gets the original data formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats(false);
 
    // Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 
    // Gets the all data formats and data conversion formats for the DataObject.
    arrayOfFormats = myDataObject.GetFormats(true);
 
    // Prints the results.
    textBox1.Text += "The data formats and conversion format(s) associated with " +
       "the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 }
 

private void GetAllFormats2()
{
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject(DataFormats.Text, 
        "Another string");

    // Gets the original data formats in the DataObject.
    String arrayOfFormats[] = myDataObject.GetFormats(false);

    // Prints the results.
    textBox1.set_Text("The format(s) associated with the data are: " + '\n');
    for (int i = 0; i < arrayOfFormats.get_Length(); i++) {
        textBox1.set_Text(textBox1.get_Text() 
            + arrayOfFormats.get_Item(i) + '\n');
    }

    // Gets the all data formats and data conversion formats for 
    // the DataObject.
    arrayOfFormats = myDataObject.GetFormats(true);

    // Prints the results.
    textBox1.set_Text(textBox1.get_Text() 
        + "The data formats and conversion format(s) "  
        + "associated with the data are: " + '\n');
    for (int i = 0; i < arrayOfFormats.get_Length(); i++) {
        textBox1.set_Text(textBox1.get_Text() 
            + arrayOfFormats.get_Item(i) + '\n');
    }
} //GetAllFormats2 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft