Initializes a new instance of the DataObject class, containing the specified data.
[Visual Basic] Overloads Public Sub New( _ ByVal data As Object _ ) [C#] public DataObject( object data ); [C++] public: DataObject( Object* data ); [JScript] public function DataObject( data : Object );
The new instance provides both the IDataObject and the Microsoft.Win32.Interop.IOleDataObject interfaces for the specified data.
CAUTION Creating an instance of DataObject with an object that implements both the IDataObject and Microsoft.Win32.Interop.IOleDataObject interfaces causes a design-time or run-time error. To avoid this problem, first convert the object either to an IDataObject or to an Microsoft.Win32.Interop.IOleDataObject.
The following example creates an instance of DataObject that contains a string. Because no class format is specified, the assumed class for the data is Object. The data is retrieved using its class as the format. The results displayed in a text box. This code assumes Button1 and TextBox1 have been instantiated.
[C#]
private void CreateDataObject3() { //Create a new data object using a string. string myString = "My text string"; DataObject myDataObject = new DataObject(myString); //Print the string in a text box. textBox1.Text = myDataObject.GetData("System.String").ToString(); }
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject Constructor Overload List | GetData | SetData | GetDataPresent