DataObject::SetData Method (String^, Boolean, Object^)
Adds the specified object to the DataObject using the specified format and indicating whether the data can be converted to another format.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- format
-
Type:
System::String^
The format associated with the data. See DataFormats for predefined formats.
- autoConvert
-
Type:
System::Boolean
true to allow the data to be converted to another format; otherwise, false.
- data
-
Type:
System::Object^
The data to store.
If you do not know the format of the target application, you can store data in multiple formats using this method.
The following code example stores data in a DataObject and specifies that the data can only be retrieved in its native format.
First, a new DataObject is created. Data in the Unicode format is stored in the DataObject, with autoConvert set to false.
Then, the DataObject is queried for the list of available data formats. Only the Unicode format is returned, although Unicode data can be converted to text and other formats.
This code requires that textBox1 has been created.
private: void AddMyData4() { // Creates a new data object, and assigns it the component. DataObject^ myDataObject = gcnew DataObject; // Adds data to the DataObject, and specifies no format conversion. myDataObject->SetData( DataFormats::UnicodeText, false, "My Unicode data" ); // Gets the data formats in the DataObject. array<String^>^ arrayOfFormats = myDataObject->GetFormats(); // Prints the results. textBox1->Text = "The format(s) associated with the data are: \n"; for ( int i = 0; i < arrayOfFormats->Length; i++ ) { textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[ i ], "\n" ); } }
Available since 1.1