Determines whether data stored in this instance is associated with, or can be converted to, the specified format.
[Visual Basic] Overloads Overridable Public Function GetDataPresent( _ ByVal format As String _ ) As Boolean [C#] public virtual bool GetDataPresent( string format ); [C++] public: virtual bool GetDataPresent( String* format ); [JScript] public function GetDataPresent( format : String ) : Boolean;
true if data stored in this instance is associated with, or can be converted to, the specified format; otherwise false.
Call this method to determine whether a format exists in this DataObject instance before calling GetData. Call GetFormats for the formats that are available in this instance.
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 determines whether data currently stored in this Object is associated with, or can be converted to, a specified format. A new instance of DataObject is initialized with a string and its associated format specified as text. Then the DataObject is queried for data associated with the text format. The result of the query is true. This code assumes Button1 has been instantiated.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Declare a DataObject Dim data1 As DataObject ' Define a boolean to hold the query results Dim isFormat As Boolean ' Create a new DataObject containing the text string whose associated format is specified as text Set data1 = New DataObject(DataFormats.Text, "Data stored as text") ' Query the DataObject for text format isFormat = data1.GetDataPresent(DataFormats.Text) ' And display the result of the query MessageBox.Show "Data can be retrieved as text: " & isFormat ' Query the DataObject for unicode format, remembering text can be converted to unicode ' and conversion is the default isformat = data1.GetDataPresent(dataFormats.UnicodeText) MessageBox.Show "Data can be retrieved as unicode: " & isFormat End Sub
The following example determines whether data previously stored in this object is associated with or can be converted to a specified format. This example makes a query for a format that the data is not stored in. First, new instance of DataObject is initialized with a string and its associated format specified as text. Because the constructor used in this example does not specify that conversion is not allowed, the data stored may be converted to other formats when it is retrieved. The object is queryed for data associated with the unicode format; text data can be converted to unicode. Because the query does not specify that conversion is not allowed, the result of the query is true. The result is displayed in a label. This code assumes Button1 is instantiated.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Declare a DataObject. Dim data1 As DataObject ' Define a string. Dim textString1 As String = "My text string" ' Define a boolean to hold the query results. Dim isFormat As Boolean ' Create a new DataObject containing the text string whose associated format is specified as text. Set data1 = New DataObject(DataFormats.Text, textString1) ' Query the DataObject for text format. isFormat = data1.GetDataPresent(DataFormats.UnicodeText) ' And determine the result of the query. If isFormat Then ' Data associated with the specified format is stored in the object. Label1.Text = "true" ' No data associated with the specified format is stored in the object. Else : Label1.Text = "false" End If End Sub
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject.GetDataPresent Overload List | SetData | System.DataObject.GetData | DataFormats | GetFormats