Stores the specified data and its associated class type in this instance.
[Visual Basic] Overloads Overridable Public Sub SetData( _ ByVal format As Type, _ ByVal data As Object _ ) [C#] public virtual void SetData( Type format, object data ); [C++] public: virtual void SetData( Type* format, Object* data ); [JScript] public function SetData( format : Type, 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 using a Type to specify the data format.
First, a new DataObject is created. Then this method stores data in the new instance, using a Type as the data format. The data is then retrieved by calling GetData using the Type to specify the data format. The result is displayed in a MessageBox.
This code assumes Button1 has been instantiated.
[C#]
private void SetMyData3() { //Create a new data object. DataObject myDataObject = new DataObject(); //Add the string to the data object. string myString = "My text string"; myDataObject.SetData(DataFormats.UnicodeText, myString); //Print the string in a text box. textBox1.Text = myDataObject.GetData(DataFormats.Text).ToString(); }
DataObject Class | DataObject Members | System.WinForms Namespace | DataObject.SetData Overload List | GetDataPresent | GetData | DataFormats | GetFormats | Type