Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IDataObject::GetDataPresent Method (String, Boolean)

Determines whether data stored in this instance is associated with the specified format, using a Boolean value to determine whether to convert the data to the format.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
bool GetDataPresent(
	String^ format, 
	bool autoConvert
)

Parameters

format
Type: System::String

The format for which to check. See DataFormats for predefined formats.

autoConvert
Type: System::Boolean

true to determine whether data stored in this instance can be converted to the specified format; false to check whether the data is in the specified format.

Return Value

Type: System::Boolean
true if the data is in, or can be converted to, the specified format; otherwise, false.

Call this method to determine whether a format exists in this DataObject before calling GetData. Call GetFormats for the formats that are available in this instance.

This method returns true when:

  • The autoConvert parameter is true and the data is in a format that can be converted to the appropriate format.

  • The autoConvert parameter is false and the data is in the appropriate format.

This method returns false when:

  • The autoConvert parameter is true and this method cannot find data in the specified format, and it cannot convert data to the specified format, or the data was stored with autoConvert set to false.

  • The autoConvert parameter is false, and data does not exist in this instance in the specified format.

NoteNote

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.

For an implementation of this method, see DataObject::GetDataPresent.

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the GetDataPresent method. First, it creates a data object (myDataObject) using a string and the Text format. Then it queries the object for data associated with the Text format, with the autoConvert parameter set to false. This trial fails, and the result is displayed in a message box labeled "Message #1." In the second trial, it sets the autoConvert parameter to true. This trial succeeds, and the result is displayed in a message box labeled "Message #2." The example assumes that you have created a Form named Form1.

private:
   void GetDataPresent3()
   {
      // Creates a new data object using a string and the Text format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"My String" );

      // Checks whether the string can be displayed with autoConvert equal to false. 
      if ( myDataObject->GetDataPresent( "System::String", false ) )
            MessageBox::Show( myDataObject->GetData( "System::String", false )->ToString(), "Message #1" );
      else
            MessageBox::Show( "Cannot convert data to the specified format with autoConvert set to false.", "Message #1" );

      // Displays the string with autoConvert equal to true.
      MessageBox::Show( "Now that autoConvert is true, you can convert " + myDataObject->GetData( "System::String", true ) + " to string format.", "Message #2" );
   }

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.