DataObject.SetData メソッド (Object)
指定したデータを、そのデータのクラスに基づく形式で、このインスタンスに格納します。
Overloads Public Overridable Sub SetData( _
ByVal data As Object _) Implements IDataObject.SetData
[C#]
public virtual void SetData(objectdata);
[C++]
public: virtual void SetData(Object* data);
[JScript]
public function SetData(
data : Object);
パラメータ
- data
格納するデータ。
実装
解説
データの形式は、データのクラスに応じて決まります。データを取り出す側のアプリケーションの形式が不明な場合は、このメソッドを使用して、データを複数の形式で格納しておくことができます。
このメソッドを使用して格納されたデータは、取得時に互換性のある形式に変換できます。
使用例
[Visual Basic, C#, C++] DataObject にデータを格納する例を次に示します。まず、新しい DataObject が作成されて、その中にコンポーネントが格納されます。次に、クラスを指定して、データを取得します。結果はテキスト ボックスに表示されます。
[Visual Basic, C#, C++] このコードは、 textBox1
が作成されていることを前提にしています。
Private Sub AddMyData3()
' Creates a component to store in the data object.
Dim myComponent As New Component()
' Creates a new data object.
Dim myDataObject As New DataObject()
' Adds the component to the DataObject.
myDataObject.SetData(myComponent)
' Prints whether data of the specified type is in the DataObject.
Dim myType As Type = myComponent.GetType()
If myDataObject.GetDataPresent(myType) Then
textBox1.Text = "Data of type " & myType.GetType().Name & _
" is present in the DataObject"
Else
textBox1.Text = "Data of type " & myType.GetType().Name & _
" is not present in the DataObject"
End If
End Sub 'AddMyData3
[C#]
private void AddMyData3() {
// Creates a component to store in the data object.
Component myComponent = new Component();
// Creates a new data object.
DataObject myDataObject = new DataObject();
// Adds the component to the DataObject.
myDataObject.SetData(myComponent);
// Prints whether data of the specified type is in the DataObject.
Type myType = myComponent.GetType();
if(myDataObject.GetDataPresent(myType))
textBox1.Text = "Data of type " + myType.GetType().Name +
" is present in the DataObject";
else
textBox1.Text = "Data of type " + myType.GetType().Name +
" is not present in the DataObject";
}
[C++]
private:
void AddMyData3() {
// Creates a component to store in the data object.
Component* myComponent = new Component();
// Creates a new data object.
DataObject* myDataObject = new DataObject();
// Adds the component to the DataObject.
myDataObject->SetData(myComponent);
// Prints whether data of the specified type is in the DataObject.
Type* myType = myComponent->GetType();
if(myDataObject->GetDataPresent(myType))
textBox1->Text = String::Format( S"Data of type {0} is present in the DataObject", myType->Name );
else
textBox1->Text = String::Format( S"Data of type {0} is not present in the DataObject", myType->Name );
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
DataObject クラス | DataObject メンバ | System.Windows.Forms 名前空間 | DataObject.SetData オーバーロードの一覧 | GetDataPresent | GetData | GetFormats