IDataObject.GetFormats Method (Boolean)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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.

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.

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
Available since 1.1
Return to top
Show: