This documentation is archived and is not being maintained.

DataObject.GetFormats Method

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

Overload List

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

[Visual Basic] Overloads Public Overridable Function GetFormats() As String() Implements IDataObject.GetFormats
[C#] public virtual string[] GetFormats();
[C++] public: virtual String* GetFormats() __gc[];
[JScript] public function GetFormats() : String[];

Returns a list of all formats that data stored in this instance 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.

[Visual Basic] Overloads Public Overridable Function GetFormats(Boolean) As String() Implements IDataObject.GetFormats
[C#] public virtual string[] GetFormats(bool);
[C++] public: virtual String* GetFormats(bool) __gc[];
[JScript] public function GetFormats(Boolean) : String[];

Example

[Visual Basic, C#, C++] The following 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.

[Visual Basic, C#, C++] This code assumes textBox1 has been created.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetFormats. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub GetAllFormats2()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
    
    ' Gets the original data formats in the DataObject.
    Dim arrayOfFormats As String() = myDataObject.GetFormats(False)
    
    ' Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " & ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) + ControlChars.Cr
    Next i 
    ' 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: " & ControlChars.Cr
        
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) + ControlChars.Cr
    Next i
End Sub 'GetAllFormats2 

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

[C++] 
private:
void GetAllFormats2() {
    // Creates a new data object using a string and the text format.
    DataObject* myDataObject = new DataObject(DataFormats::Text, S"Another string");
 
    // Gets the original data formats in the DataObject.
    String* arrayOfFormats[] = myDataObject->GetFormats(false);
 
    // Prints the results.
    textBox1->Text = S"The format(s) associated with the data are: \n";
    for(int i=0; i<arrayOfFormats->Length; i++)
       textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[i], S"\n" );
 
    // Gets the all data formats and data conversion formats for the DataObject.
    arrayOfFormats = myDataObject->GetFormats(true);
 
    // Prints the results.
    textBox1->Text = String::Format( S"{0}The data formats and conversion format(s) associated with the data are: \n", textBox1->Text );
    for(int i=0; i<arrayOfFormats->Length; i++)
       textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[i], S"\n" );
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataObject Class | DataObject Members | System.Windows.Forms Namespace

Show: