DataObject.GetFormats Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
virtual cli::array <System::String ^> ^ GetFormats();
public virtual string[] GetFormats ();
abstract member GetFormats : unit -> string[]
override this.GetFormats : unit -> string[]
Public Overridable Function GetFormats () As String()
Returns
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.
private:
void GetAllFormats()
{
// Creates a new data object using a string and the text format.
DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"Another string" );
// Gets all the data formats and data conversion formats in the DataObject.
array<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 = String::Concat( textBox1->Text, arrayOfFormats[ i ], "\n" );
}
}
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';
}
Private Sub GetAllFormats()
' Creates a new data object using a string and the text format.
Dim myDataObject As New DataObject(DataFormats.Text, "Another string")
' Gets all the data formats and data conversion formats in the DataObject.
Dim arrayOfFormats As String() = myDataObject.GetFormats()
' 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
End Sub
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
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.
public:
virtual cli::array <System::String ^> ^ GetFormats(bool autoConvert);
public virtual string[] GetFormats (bool autoConvert);
abstract member GetFormats : bool -> string[]
override this.GetFormats : bool -> string[]
Public Overridable Function GetFormats (autoConvert As Boolean) As String()
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
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.
private:
void GetAllFormats2()
{
// Creates a new data object using a string and the text format.
DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"Another string" );
// Gets the original data formats in the DataObject.
array<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 = String::Concat( 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 = String::Concat( 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 = String::Concat( textBox1->Text, arrayOfFormats[ i ], "\n" );
}
}
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';
}
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
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.