DataObject.GetFormats Method

Definition

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

Overloads

GetFormats()

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

GetFormats(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.

GetFormats()

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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

C#
public virtual string[] GetFormats();

Returns

String[]

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

Implements

Examples

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.

C#
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';
 }

Remarks

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

Note

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.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

GetFormats(Boolean)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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.

C#
public virtual string[] GetFormats(bool autoConvert);

Parameters

autoConvert
Boolean

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.

Returns

String[]

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

Implements

Examples

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.

C#
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';
 }

Remarks

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

Note

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.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10