Stores the specified data and its associated format in this instance, using autoConvert to specify whether the data can be converted to another format.
[Visual Basic] Overloads Overridable Public Sub SetData( _ ByVal format As String, _ ByVal autoConvert As Boolean, _ ByVal data As Object _ ) [C#] public virtual void SetData( string format, bool autoConvert, object data ); [C++] public: virtual void SetData( String* format, bool autoConvert, Object* data ); [JScript] public function SetData( format : String, autoConvert : Boolean, data : Object );
If you do not know the format of the target application, you can store data in multiple formats using this method.
The following example stores data in a DataObject and specifies that the data can only be retrieved by its native format.
First, a new DataObject is created. Then, data, in the Unicode format, is stored in the DataObject, with autoConvert set to false.
Then, the DataObject is queried for the list of data formats. Only the Unicode format is returned, although Unicode data can be converted to text and other formats. This code assumes Button1 has been instantiated.
[C#]
private void CreateDataObject2() { //Create a new data object. DataObject setMyData = 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 | GetData | GetDataPresent | GetFormats | DataFormats