Stores the specified data and its associated format in this instance.
[Visual Basic] Overloads Overridable Public Sub SetData( _ ByVal format As String, _ ByVal data As Object _ ) [C#] public virtual void SetData( string format, object data ); [C++] public: virtual void SetData( String* format, Object* data ); [JScript] public function SetData( format : String, data : Object );
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.
The following example stores data in a DataObject, specifying its format.
First, a new instance of DataObject is created. Then, a string is stored in the DataObject with Unicode as its associated format.
Finally, the data is retrieved by specifying the text format, since the default is to convert the data when the final format is compatible. 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) ' Create the DataObject Dim data1 As DataObject Set data1 = New DataObject ' Store a string, specifying the Unicode format. data1.SetData DataFormats.UnicodeText, "text string 2" ' Retrieve the data by specifying Unicode and display it in a label. MessageBox.Show data1.GetData(DataFormats.Text) End Sub
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject.SetData Overload List | GetData | GetDataPresent | GetFormats | DataFormats