Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataObject Constructor

.NET Framework 1.1

Initializes a new instance of the DataObject class.

Overload List

Initializes a new instance of the DataObject class, which can store arbitrary data.

[Visual Basic] Public Sub New()
[C#] public DataObject();
[C++] public: DataObject();
[JScript] public function DataObject();

Initializes a new instance of the DataObject class, containing the specified data.

[Visual Basic] Public Sub New(Object)
[C#] public DataObject(object);
[C++] public: DataObject(Object*);
[JScript] public function DataObject(Object);

Initializes a new instance of the DataObject class, containing the specified data and its associated format.

[Visual Basic] Public Sub New(String, Object)
[C#] public DataObject(string, object);
[C++] public: DataObject(String*, Object*);
[JScript] public function DataObject(String, Object);

Example

[Visual Basic, C#, C++] The following example creates an instance of the DataObject class using a string that is specified as the string type. The data is retrieved from the instance by specifying its format as text. The results are displayed in a text box. This code assumes textBox1 has been created.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the DataObject constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub CreateTextDataObject2()
    ' Creates a new data object using a string.
    Dim myString As String = "My next text string"
    Dim myDataObject As New DataObject("System.String", myString)
    
    ' Prints the string in a text box.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString()
End Sub 'CreateTextDataObject2

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

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

[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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.