DataObject Constructors

Definition

Initializes a new instance of the DataObject class.

Overloads

DataObject()

Initializes a new instance of the DataObject class.

DataObject(Object)

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

DataObject(String, Object)

Initializes a new instance of the DataObject class and adds the specified object in the specified format.

DataObject()

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class.

C#
public DataObject();

Examples

The following code example creates a DataObject and adds data to it. The example then retrieves and displays the data. This code requires that textBox1 has been created.

C#
private void CreateDefaultDataObject() {
    // Creates a data object.
    DataObject myDataObject;
 
    // Assigns the string to the data object.
    string myString = "My text string";
    myDataObject = new DataObject(myString);
 
    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
 }

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DataObject(Object)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

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

C#
public DataObject(object data);

Parameters

data
Object

The data to store.

Examples

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.

C#
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();
 }

Remarks

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.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DataObject(String, Object)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class and adds the specified object in the specified format.

C#
public DataObject(string format, object data);

Parameters

format
String

The format of the specified data. See DataFormats for predefined formats.

data
Object

The data to store.

Examples

The following code example creates a DataObject class using a string that is specified as the string type. The data is retrieved from the DataObject by specifying its format as text. The results are displayed in a text box. This code requires that textBox1 has been created.

C#
private void CreateTextDataObject2() {
    // Creates a new data object using a string.
    string myString = "My next text string";
    DataObject myDataObject = new DataObject("System.String", myString);
 
    // Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
 }

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9