Stores the specified data and its associated format in this instance.
Stores the specified data and its associated format in this instance.
[Visual Basic] Overloads Overridable Public Sub SetData(String, Object)
[C#] public virtual void SetData(String, Object);
[C++] public: virtual void SetData(String*, Object);
[JScript] public function SetData(String, Object);
Stores the specified data and its associated class type in this instance.
[Visual Basic] Overloads Overridable Public Sub SetData(Type, Object)
[C#] public virtual void SetData(Type, Object);
[C++] public: virtual void SetData(Type*, Object);
[JScript] public function SetData(Type, Object);
Stores the specified data in this instance, using the class of the data for the format.
[Visual Basic] Overloads Overridable Public Sub SetData(Object)
[C#] public virtual void SetData(Object);
[C++] public: virtual void SetData(Object*);
[JScript] public function SetData(Object);
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(String, Boolean, Object)
[C#] public virtual void SetData(String, bool, Object);
[C++] public: virtual void SetData(String*, bool, Object);
[JScript] public function SetData(String, Boolean, Object);
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.
Note This example shows how to use one of the overloaded versions of SetData. For other examples that may be available, see the individual overload topics.
[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