Retrieves the data associated with the specified data format.
Retrieves the data associated with the specified class type format.
[Visual Basic] Overloads Overridable Public Function GetData(Type) As Object
[C#] public virtual object GetData(Type);
[C++] public: virtual Object* GetData(Type*);
[JScript] public function GetData(Type) : Object;
Retrieves the data associated with the specified data format.
[Visual Basic] Overloads Overridable Public Function GetData(String) As Object
[C#] public virtual object GetData(String);
[C++] public: virtual Object* GetData(String*);
[JScript] public function GetData(String) : Object;
Retrieves the data associated with the specified data format, using autoConvert to determine whether to convert the data to the format.
[Visual Basic] Overloads Overridable Public Function GetData(String, Boolean) As Object
[C#] public virtual object GetData(String, bool);
[C++] public: virtual Object* GetData(String*, bool);
[JScript] public function GetData(String, Boolean) : Object;
The following example retrieves the data stored in a DataObject, using autoConvert to specify whether to convert the data format.
First, a new DataObject is created with text data. Then, we try to retrieve the data, specifying its format as Unicode and no format conversion, that is autoConvert is false. This operation fails because there is no Unicode data in the DataObject.
Next, we try to retrieve the data again, specifying its format as Unicode and with autoConvert set to true. This operation succeeds and the results are displayed in a MessageBox.
This code assumes Button1 has been instantiated.
Note This example shows how to use one of the overloaded versions of GetData. For other examples that may be available, see the individual overload topics.
[C#]
private void GetMyData() { //Create a new data object using a string and the text format. string myString = "My new text string"; DataObject myDataObject = new DataObject(DataFormats.Text, myString); //Print the string in a text box with autoconvert = false. if(myDataObject.GetData(DataFormats.UnicodeText, false) != null) { //Print the string in a text box. textBox1.Text = myDataObject.GetData(DataFormats.UnicodeText, false).ToString() + '\n'; } else textBox1.Text = "Could not convert data to specified format" + '\n'; //Print the string in a text box with autoconvert = true. textBox1.Text += myDataObject.GetData(DataFormats.UnicodeText, true).ToString(); }
DataObject Class | DataObject Members | System.WinForms Namespace