Gets a list of all formats that data stored in this instance is associated with or can be converted to, using autoConvert to determine whether to retrieve all formats that the data can be converted to or only native data formats.
[Visual Basic] Overloads Overridable Public Function GetFormats( _ ByVal autoConvert As Boolean _ ) As String () [C#] public virtual string[] GetFormats( bool autoConvert ); [C++] public: virtual String* GetFormats( bool autoConvert ) []; [JScript] public function GetFormats( autoConvert : Boolean ) : 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 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 compatable with the stored format. For example, data stored as Unicode can be converted to text.
The following example queries a DataObject for the formats associated with its data. The first query specifies autoConvert as false, so only the native format of the data is returned.
The second query specifies autoConvert as true, so the list of formats includes the formats that the data can be converted to. This code assumes Button1 has been instantiated.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Create a new DataObject containing data associated with text format. Dim data1 As DataObject Set data1 = New DataObject(DataFormats.Text, "My format test string") ' Declare an array of strings to hold data formats. Dim arrayOfFormats() As String ' Query the DataObject for only the stored data formats and display the results. arrayOfFormats = data1.GetFormats(False) ' Declare a variable to interate through the array. Dim i As Integer ' Declare a string to display formats. Dim displayFormats As String For i = LBound(arrayOfFormats) To UBound(arrayOfFormats) displayFormats &= arrayOfFormats(i) & vbnewline Next MessageBox.Show "The format(s) associated with the data are: " & displayFormats ' Query the DataObject for the data formats and the data conversion formats. arrayofformats = data1.GetFormats(True) ' And display the formats. displayFormats = "" For i = LBound(arrayOfFormats) To UBound(arrayOfFormats) displayFormats &= arrayOfFormats(i) & vbnewline Next MessageBox.Show "The format(s) associated with or that " & _ "the data can be converted to are: " & displayFormats End Sub
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject.GetFormats Overload List | GetData | SetData | DataFormats | GetDataPresent