DataObject::GetDataPresent Method (Type^)
Determines whether data stored in this DataObject is associated with, or can be converted to, the specified format.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- format
-
Type:
System::Type^
A Type representing the format to check for.
Return Value
Type: System::Booleantrue if data stored in this DataObject is associated with, or can be converted to, the specified format; otherwise, false.
Implements
IDataObject::GetDataPresent(Type^)Call this method to determine whether a format exists before calling GetData. Call GetFormats for the formats that are available in this DataObject.
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. |
Note |
|---|
If no data can be retrieved, no exception will be thrown. Instead, false will be returned. |
The following code example determines whether data of the specified type exists in a DataObject, or whether the data can be converted to the specified type. The result is displayed in a text box. The code requires that textBox1 has been created.
private: void GetIfPresent2() { // Creates a component to store in the data object. Component^ myComponent = gcnew Component; // Creates a new data object and assigns it the component. DataObject^ myDataObject = gcnew DataObject( myComponent ); // Creates a type to store the type of data. Type^ myType = myComponent->GetType(); // Determines if the DataObject has data of the Type format. textBox1->Text = String::Concat( "Is the specified data type available ", "in the DataObject? ", myDataObject->GetDataPresent( myType ), "\n" ); // Retrieves the data using its type format, and displays the type. Object^ myObject = myDataObject->GetData( myType ); textBox1->Text = String::Concat( textBox1->Text, "The data type stored ", "in the DataObject is: ", myObject->GetType()->Name ); }
Available since 1.1
