Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IDataObject.GetFormats Method (Boolean)

Gets a list of all formats that data stored in this instance is associated with or can be converted to, using a Boolean value to determine whether to retrieve all formats that the data can be converted to or only native data formats.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
string[] GetFormats(
	bool autoConvert
)

Parameters

autoConvert
Type: System.Boolean

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

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 UnicodeText format. Then it makes two queries to get the formats associated with the data. In the first query, it sets the autoConvert parameter to false : in this case, only the native format of the data is returned. In the second query, it sets the autoConvert parameter to true, so that it gets the list of formats, including the formats that the data can be converted to. In each case, the resulting list is displayed in a message box. This example assumes that you have created a Form named Form1.

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

    // Gets the original data formats in the data object by setting the automatic 
    // conversion parameter to false.
    String[] myFormatsArray = myDataObject.GetFormats(false);

    // Stores the results in a string. 
    string theResult = "The original format associated with the data is:\n";
    for(int i = 0; i < myFormatsArray.Length; i++)
        theResult += myFormatsArray[i] + '\n';

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

    // Stores the results in the string.
    theResult += "\nThe data format(s) and conversion format(s) associated with " +
        "the data are:\n";
    for(int i = 0; i < myFormatsArray.Length; i++)
        theResult += myFormatsArray[i] + '\n';

    // Displays the results.
    MessageBox.Show(theResult);
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.