Export (0) Print
Expand All

DataObject.SetData Method (String, Boolean, Object)

Adds the specified object to the DataObject using the specified format and indicating whether the data can be converted to another format.

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

public virtual void SetData(
	string format,
	bool autoConvert,
	Object data
)

Parameters

format
Type: System.String

The format associated with the data. See DataFormats for predefined formats.

autoConvert
Type: System.Boolean

true to allow the data to be converted to another format; otherwise, false.

data
Type: System.Object

The data to store.

Implements

IDataObject.SetData(String, Boolean, Object)

If you do not know the format of the target application, you can store data in multiple formats using this method.

The following code example stores data in a DataObject and specifies that the data can only be retrieved in its native format.

First, a new DataObject is created. Data in the Unicode format is stored in the DataObject, with autoConvert set to false.

Then, the DataObject is queried for the list of available data formats. Only the Unicode format is returned, although Unicode data can be converted to text and other formats.

This code requires that textBox1 has been created.

private void AddMyData4() {
    // Creates a new data object, and assigns it the component.
    DataObject myDataObject = new DataObject();

    // Adds data to the DataObject, and specifies no format conversion.
    myDataObject.SetData(DataFormats.UnicodeText, false, "My Unicode data");

    // Gets the data formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats();

    // Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 }
 

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft