IDataObject.SetData Method (String, Boolean, Object)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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)

Sub SetData (
	format As String,
	autoConvert As Boolean,
	data As Object


Type: System.String

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

Type: System.Boolean

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

Type: System.Object

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 Sub SetData4()
    ' Creates a new data object.
    Dim myDataObject As 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.
    Dim arrayOfFormats As [String]() = myDataObject.GetFormats()

    ' Stores the results in a string.
    Dim theResult As String = "The format(s) associated with the data are:" + _
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        theResult += arrayOfFormats(i) + ControlChars.Cr
    Next i
    ' Show the results in a message box. 
End Sub 'SetData4 

.NET Framework
Available since 1.1
Return to top