Export (0) Print
Expand All

IDataObject.GetFormats Method

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

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

string[] GetFormats()

Return Value

Type: System.String[]
An array of the names that represents 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 the GetData method. See the DataFormats class 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.

For an implementation of this method, see DataObject.GetFormats.

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetFormats method. First, it creates a data object (myDataObject) using a string and the Text format. Then it retrieves all the data formats and data conversion formats in the data object, and displays the resulting list in a message box. This example assumes that you have created a Form named Form1.


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

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

    // Creates the string that contains the formats.
    string theResult = "The format(s) associated with the data are: " + '\n';
    for(int i = 0; i < allFormats.Length; i++)
        theResult += allFormats[i] + '\n';
    // Displays the result in a message box.
    MessageBox.Show(theResult);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft