Export (0) Print
Expand All

IDataObject.SetData Method (String, Boolean, Object)

Stores the specified data and its associated format in this instance, using a Boolean value to specify whether the data can be converted to another format.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

void SetData (
	string format,
	bool autoConvert,
	Object data
)
void SetData (
	String format, 
	boolean autoConvert, 
	Object data
)
function SetData (
	format : String, 
	autoConvert : boolean, 
	data : Object
)
Not applicable.

Parameters

format

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

autoConvert

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

data

The data to store.

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

For an implementation of this method, see DataObject.SetData.

This example uses the DataObject class, which implements IDataObject, to demonstrate the use of the SetData method. First, it creates a data object (myDataObject) and stores a UnicodeText string in it, with the autoConvert parameter set to false. Then it retrieves the format(s) associated with the data stored in the object and displays the result in a message box. The only format associated with the data is the UnicodeText format. This example assumes that you have created a Form named Form1.

private void SetData4() 
{
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds UnicodeText string to the object, and set the autoConvert 
    // parameter to false.
    myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");
 
    // Gets the data format(s) in the data object.
    String[] arrayOfFormats = myDataObject.GetFormats();
 
    // Stores the results in a string.
    string theResult = "The format(s) associated with the data are:" + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
        theResult += arrayOfFormats[i] + '\n';
    
    // Show the results in a message box. 
    MessageBox.Show(theResult);

}

// Creates a new data object.
DataObject myDataObject = new DataObject();
     
// Adds UnicodeText string to the object, and set the autoConvert 
// parameter to false.
myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");

// Gets the data format(s) in the data object.
String arrayOfFormats[] = myDataObject.GetFormats();

// Stores the results in a string.
String theResult = "The format(s) associated with the data are:" + '\n';
for (int i = 0; i < arrayOfFormats.length; i++) {
    theResult += arrayOfFormats[i] + '\n';
}
// Show the results in a message box. 
MessageBox.Show(theResult);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft