Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataObject.SetData Method

Stores the specified format and data in this instance.

Overload List

Stores the specified data in this instance, using the class of the data for the format.

[Visual Basic] Overloads Public Overridable Sub SetData(Object) Implements IDataObject.SetData
[C#] public virtual void SetData(object);
[C++] public: virtual void SetData(Object*);
[JScript] public function SetData(Object);

Stores the specified format and data in this instance.

[Visual Basic] Overloads Public Overridable Sub SetData(String, Object) Implements IDataObject.SetData
[C#] public virtual void SetData(string, object);
[C++] public: virtual void SetData(String*, Object*);
[JScript] public function SetData(String, Object);

Stores the specified data and its associated class type in this instance.

[Visual Basic] Overloads Public Overridable Sub SetData(Type, Object) Implements IDataObject.SetData
[C#] public virtual void SetData(Type, object);
[C++] public: virtual void SetData(Type*, Object*);
[JScript] public function SetData(Type, Object);

Stores the specified format and data in this instance, using the automatic conversion parameter to specify whether the data can be converted to another format.

[Visual Basic] Overloads Public Overridable Sub SetData(String, Boolean, Object) Implements IDataObject.SetData
[C#] public virtual void SetData(string, bool, object);
[C++] public: virtual void SetData(String*, bool, Object*);
[JScript] public function SetData(String, Boolean, Object);

Example

[Visual Basic, C#, C++] The following example stores data in a DataObject and specifies that the data can only be retrieved in its native format.

[Visual Basic, C#, C++] First, a new DataObject is created. Data in the Unicode format is stored in the DataObject, with autoConvert set to false.

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] This code assumes textBox1 has been created.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of SetData. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub AddMyData4()
    ' Creates a new data object, and assigns it the component.
    Dim myDataObject As 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.
    Dim arrayOfFormats As String() = myDataObject.GetFormats()
    
    ' Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " & ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) & ControlChars.Cr
    Next i
End Sub 'AddMyData4 

[C#] 
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';
 }
 

[C++] 
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, S"My Unicode data");
 
    // Gets the data formats in the DataObject.
    String* arrayOfFormats[] = myDataObject->GetFormats();
 
    // Prints the results.
    textBox1->Text = S"The format(s) associated with the data are: \n";
    for(int i=0; i<arrayOfFormats->Length; i++)
       textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[i], S"\n" );
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataObject Class | DataObject Members | System.Windows.Forms Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft