DataObject.GetData メソッド

定義

指定したデータ形式に関連付けられているデータを返します。

オーバーロード

名前 説明
GetData(String, Boolean)

自動変換パラメーターを使用して、データを形式に変換するかどうかを判断して、指定したデータ形式に関連付けられているデータを返します。

GetData(String)

指定したデータ形式に関連付けられているデータを返します。

GetData(Type)

指定したクラス型形式に関連付けられているデータを返します。

GetData(String, Boolean)

自動変換パラメーターを使用して、データを形式に変換するかどうかを判断して、指定したデータ形式に関連付けられているデータを返します。

public:
 virtual System::Object ^ GetData(System::String ^ format, bool autoConvert);
public virtual object GetData(string format, bool autoConvert);
abstract member GetData : string * bool -> obj
override this.GetData : string * bool -> obj
Public Overridable Function GetData (format As String, autoConvert As Boolean) As Object

パラメーター

format
String

取得するデータの形式。 定義済みの形式については、 DataFormats を参照してください。

autoConvert
Boolean

true 指定された形式に変換するデータに;それ以外の場合は false

返品

指定した形式に関連付けられているデータ、または null

実装

次のコード例では、autoConvert パラメーターを使用してデータ形式を変換するかどうかを指定して、DataObjectに格納されているデータを取得します。

まず、テキスト データを使用して新しい DataObject が作成されます。 次に、データの取得を試み、その形式を文字列として指定し、形式変換を行いません。つまり、 autoConvert パラメーターは falseDataObjectに文字列データがないため、この操作は失敗します。

次に、 autoConvert パラメーターを true に設定して、データの取得を再試行します。 この操作は成功し、結果は MessageBoxに表示されます。

このコードでは、 textBox1 が作成されている必要があります。

private:
   void GetMyData3()
   {
      // Creates a new data object using a string and the text format.
      String^ myString = "My new text string";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );
      
      // Prints the string in a text box with autoconvert = false.
      if ( myDataObject->GetData( "System.String", false ) != 0 )
      {
         // Prints the string in a text box.
         textBox1->Text = String::Concat(
            myDataObject->GetData( "System.String", false )->ToString(), "\n" );
      }
      else
      {
         textBox1->Text = "Could not find data of the specified format\n";
      }
      
      // Prints the string in a text box with autoconvert = true.
      textBox1->Text = String::Concat(
            textBox1->Text, myDataObject->GetData( "System.String", true )->ToString() );
   }
private void GetMyData3() {
    // Creates a new data object using a string and the text format.
    string myString = "My new text string";
    DataObject myDataObject = new DataObject(DataFormats.Text, myString);
 
    // Prints the string in a text box with autoconvert = false.
    if(myDataObject.GetData("System.String", false) != null) {
       // Prints the string in a text box.
       textBox1.Text = myDataObject.GetData("System.String", false).ToString() + '\n';
    } else
        {
            textBox1.Text = "Could not find data of the specified format" + '\n';
        }

        // Prints the string in a text box with autoconvert = true.
        textBox1.Text += myDataObject.GetData("System.String", true).ToString();
 }
Private Sub GetMyData3()
    ' Creates a new data object using a string and the text format.
    Dim myString As String = "My new text string"
    Dim myDataObject As New DataObject(DataFormats.Text, myString)
    
    ' Prints the string in a text box with autoconvert = false.
    If (myDataObject.GetData("System.String", False) IsNot Nothing) Then
        ' Prints the string in a text box.
        textBox1.Text = myDataObject.GetData("System.String", False).ToString() & ControlChars.Cr
    Else
        textBox1.Text = "Could not find data of the specified format" & ControlChars.Cr
    End If 
    ' Prints the string in a text box with autoconvert = true.
    textBox1.Text += myDataObject.GetData("System.String", True).ToString()
End Sub

注釈

autoConvert パラメーターがtrueされていて、このメソッドが指定した形式のデータを見つけることができない場合は、データを形式に変換しようとします。 データを指定した形式に変換できない場合、または自動変換を false に設定してデータが格納されている場合、このメソッドは nullを返します。

autoConvert パラメーターがfalseの場合、このメソッドは指定した形式のデータを返します。この形式のデータが見つからない場合はnullします。

データが形式に関連付けられているか、または形式に変換できるかを判断するには、GetDataを呼び出す前にGetDataPresentを呼び出します。 このDataObjectに格納されているデータの有効な形式の一覧については、GetFormatsを呼び出します。

Note

データは、その変換が許可されることを指定して格納されている場合、および要求された形式が格納された形式と互換性がある場合は、別の形式に変換できます。 たとえば、Unicode として格納されているデータをテキストに変換できます。

formatHtml の場合、このメソッドは、4.5 以降 .NETをターゲットとするアプリケーションでは UTF-8 でエンコードされた文字列、および 4.0 以下をターゲットとするアプリケーションでは ANSI エンコード文字列.NET返します。

こちらもご覧ください

適用対象

GetData(String)

指定したデータ形式に関連付けられているデータを返します。

public:
 virtual System::Object ^ GetData(System::String ^ format);
public virtual object GetData(string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Overridable Function GetData (format As String) As Object

パラメーター

format
String

取得するデータの形式。 定義済みの形式については、 DataFormats を参照してください。

返品

指定した形式に関連付けられているデータ、または null

実装

次のコード例では、 DataObjectに格納されているデータを取得します。 まず、テキスト データを使用して新しい DataObject が作成されます。 次に、データが取得され、その形式が文字列として指定され、テキスト ボックスに表示されます。

このコードでは、 textBox1 が作成されている必要があります。

private:
   void AddMyData3()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object.
      DataObject^ myDataObject = gcnew 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::Concat( "Data of type ", myType,
            " is present in the DataObject" );
      }
      else
      {
         textBox1->Text = String::Concat( "Data of type ", myType,
            " is not present in the DataObject" );
      }
   }
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.ToString() + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.ToString() +
       " is not present in the DataObject";
 }
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.ToString() & _
            " is present in the DataObject"
    Else
        textBox1.Text = "Data of type " & myType.ToString() & _
            " is not present in the DataObject"
    End If
End Sub

注釈

このメソッドは、指定された形式のデータを見つけることができない場合は、データを形式に変換しようとします。 指定した形式にデータを変換できない場合、または自動変換を false に設定してデータが格納されている場合、このメソッドは nullを返します。

データが形式に関連付けられているか、または形式に変換できるかを判断するには、GetDataを呼び出す前にGetDataPresentを呼び出します。 このDataObjectに格納されているデータの有効な形式の一覧については、GetFormatsを呼び出します。

Note

データは、その変換が許可されることを指定して格納されている場合、および要求された形式が格納された形式と互換性がある場合は、別の形式に変換できます。 たとえば、Unicode として格納されているデータをテキストに変換できます。

formatHtml の場合、このメソッドは、4.5 以降 .NETをターゲットとするアプリケーションでは UTF-8 でエンコードされた文字列、および 4.0 以下をターゲットとするアプリケーションでは ANSI エンコード文字列.NET返します。

こちらもご覧ください

適用対象

GetData(Type)

指定したクラス型形式に関連付けられているデータを返します。

public:
 virtual System::Object ^ GetData(Type ^ format);
public virtual object GetData(Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
Public Overridable Function GetData (format As Type) As Object

パラメーター

format
Type

取得するデータの形式を表す Type

返品

指定した形式に関連付けられているデータ、または null

実装

次のコード例では、 DataObjectに格納されているデータを取得します。 まず、コンポーネントを使用して新しい DataObject が作成されます。 次に、データが取得され、その型が指定されます。 取得したデータの型がテキスト ボックスに表示されます。

このコードでは、 textBox1 が作成されている必要があります。

private:
   void GetMyData()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject( myComponent );
      
      // Creates a type to store the type of data.
      Type^ myType = myComponent->GetType();
      
      // Retrieves the data using myType to represent its type.
      Object^ myObject = myDataObject->GetData( myType );
      if ( myObject != nullptr )
      {
         textBox1->Text = String::Format( "The data type stored in the DataObject is: {0}",
            myObject->GetType()->Name );
      }
      else
      {
         textBox1->Text = "Data of the specified type was not stored in the DataObject.";
      }
   }
private void GetMyData() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object and assigns it the component.
    DataObject myDataObject = new DataObject(myComponent);
 
    // Creates a type to store the type of data.
    Type myType = myComponent.GetType();
 
    // Retrieves the data using myType to represent its type.
    Object myObject = myDataObject.GetData(myType);
    if(myObject != null)
       textBox1.Text = "The data type stored in the DataObject is: " +
       myObject.GetType().Name;
    else
       textBox1.Text = "Data of the specified type was not stored " +
       "in the DataObject.";
 }
Private Sub GetMyData()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object and assigns it the component.
    Dim myDataObject As New DataObject(myComponent)
    
    ' Creates a type to store the type of data.
    Dim myType As Type = myComponent.GetType()
    
    ' Retrieves the data using myType to represent its type.
    Dim myObject As Object = myDataObject.GetData(myType)
    If (myObject IsNot Nothing) Then
        textBox1.Text = "The data type stored in the DataObject is: " & myObject.GetType().Name
    Else
        textBox1.Text = "Data of the specified type was not stored " & "in the DataObject."
    End If
End Sub

注釈

このメソッドは、指定された形式のデータを見つけることができない場合は、データを形式に変換しようとします。 指定した形式にデータを変換できない場合、または自動変換を false に設定してデータが格納されている場合、このメソッドは nullを返します。

データが形式に関連付けられているか、または形式に変換できるかを判断するには、GetDataを呼び出す前にGetDataPresentを呼び出します。 このDataObjectに格納されているデータの有効な形式の一覧については、GetFormatsを呼び出します。

Note

データは、その変換が許可されることを指定して格納されている場合、および要求された形式が格納された形式と互換性がある場合は、別の形式に変換できます。 たとえば、Unicode として格納されているデータをテキストに変換できます。

こちらもご覧ください

適用対象