DataObject Constructor (Object)


Initializes a new instance of the DataObject class and adds the specified object to it.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public DataObject(
	object data


Type: System.Object

The data to store.

You can add data in any format to the DataObject when you use this constructor, or you can add data as an IDataObject to provide multiple formats at once. If you are familiar with COM programming, you can also add a data object that implements the COM IDataObject interface. For more information, see IDataObject in the MSDN library at

The following code example creates a DataObject that contains a string. The data is retrieved using its data format. The results are displayed in a text box. This code requires that textBox1 has been created.

private void CreateTextDataObject() {
    // Creates a new data object using a string.
    string myString = "My text string";
    DataObject myDataObject = new DataObject(myString);

    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();

.NET Framework
Available since 1.1
Return to top