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.SetData (Object)

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

[Visual Basic]
Overloads Overridable Public Sub SetData( _
   ByVal data As Object _
)
[C#]
public virtual void SetData(
   object data
);
[C++]
public: virtual void SetData(
   Object* data
);
[JScript]
public function SetData(
   data : Object
);

Parameters

data
The data to store.

Remarks

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

Data stored using this method can be converted to a compatible format when it is retrieved.

Example

The following example stores data in a DataObject. First, a new DataObject is created and data is stored in it. Then, the data is retrieved by specifying the class. The result is displayed in a MessageBox.

This code assumes Button1 has been instantiated.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)    'Declare a new DataObject
   ' Create a new DataObject.
   Dim data1 As DataObject
   Set data1 = New DataObject

   ' Create a new Component to store in the DataObject.
   Dim component1 As Component
   Set component1 = New Component

   ' Create a Type specifying the format associated with the data.
   Dim myType1 As System.Type
   Set mytype1 = component1.GetType

   ' Store the Component in the DataObject.
   data1.SetData component1

   ' And retrieve it.
   Dim myObj As Object
   Set myobj = data1.GetData(myType1)

   ' Verify data was returned, get its type, and display it.
   If Not (myObj Is Nothing) Then
      Set mytype1 = myobj.GetType
      MessageBox.Show "Type of the object retrieved is: " & mytype1.tostring
   Else : MessageBox.Show "No object was retrieved"
   End If
End Sub

See Also

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