DataObject.GetFormats Method ()

 

Returns a list of all formats that data stored in this DataObject is associated with or can be converted to.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual string[] GetFormats()

Return Value

Type: System.String[]

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.

System_CAPS_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, and the formats that the data can be converted to. The resulting list is displayed in a text box. This code requires that textBox1 has been created.

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

    // Gets all the data formats and data conversion formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats();

    // 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';
 }

.NET Framework
Available since 1.1
Return to top
Show: