Retrieves the data associated with the specified class type format.
[Visual Basic] Overloads Overridable Public Function GetData( _ ByVal format As Type _ ) As Object [C#] public virtual object GetData( Type format ); [C++] public: virtual Object* GetData( Type* format ); [JScript] public function GetData( format : Type ) : Object;
The data associated with the specified format, or a null reference (in Visual Basic Nothing).
If this method cannot find data in the specified format, it attempts to convert the data to the format. If the data cannot be converted to the specified format, or if the data was stored with autoConvert set to false, this method returns a null reference (Nothing).
To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Call GetFormats for a list of valid formats for the data stored 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 retrieves the data stored in a DataObject.
First, a new DataObject is created with text data. Then, the data is retrieved, specifying its format as text, and displayed in a text box.
Next, we retrieve the data again, specifying its format as Unicode, which is a format that text can be converted to. The data is displayed in a text box.
This code assumes Button1 and TextBox1 have been instantiated.
[C#]
private void GetMyData2() { //Create a new data object using a string and the text format. string myString = "My text string"; DataObject myDataObject = new DataObject(DataFormats.Text, myString); //Print the string in a text box. textBox1.Text += myDataObject.GetData("System.String").ToString(); }
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject.GetData Overload List | SetData | Type | GetDataPresent | DataFormats | System.WinForms.DataObject.GetFormat