NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataObject Constructor (String, Object)

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

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

Parameters

format
The class type associated with the data. See DataFormats for the predefined formats.
data
The data to store.

Remarks

The new instance provides both the IDataObject and the Microsoft.Win32.Interop.IOleDataObject interfaces for the specified data.

CAUTION   Creating an instance of DataObject with an object that implements both the IDataObject and Microsoft.Win32.Interop.IOleDataObject interfaces causes a design-time or run-time error. To avoid this problem, first convert the object either to an IDataObject or to an Microsoft.Win32.Interop.IOleDataObject.

Example [C#]

The following example creates an instance of the DataObject class using a string that is specified as text format. The data is retrieved from the instance by specifying its format as text. Then the data is displayed in a text box. This code assumes Button1 and TextBox1 have been instantiated.

[C#]

private void CreateDataObject() {
   //Create a new data object using a string.
   string myString = "My text string";
   DataObject myDataObject = new DataObject(DataFormats.Text, myString);

   //Print the string in a text box.
   textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString();
}

See Also

DataObject Class | DataObject Members | System.WinForms Namespace | DataObject Constructor Overload List | GetData | SetData | GetDataPresent