IDataObject.GetDataPresent Metoda

Definice

Určuje, zda jsou data uložená v této instanci přidružena k zadanému formátu.

Přetížení

GetDataPresent(String)

Určuje, jestli jsou data uložená v této instanci přidružená nebo lze převést na zadaný formát.

GetDataPresent(Type)

Určuje, jestli jsou data uložená v této instanci přidružená nebo lze převést na zadaný formát.

GetDataPresent(String, Boolean)

Určuje, zda jsou data uložená v této instanci přidružená k zadanému formátu pomocí logické hodnoty k určení, zda se mají data převést do formátu.

GetDataPresent(String)

Určuje, jestli jsou data uložená v této instanci přidružená nebo lze převést na zadaný formát.

public:
 bool GetDataPresent(System::String ^ format);
public bool GetDataPresent (string format);
abstract member GetDataPresent : string -> bool
Public Function GetDataPresent (format As String) As Boolean

Parametry

format
String

Formát, pro který se má zkontrolovat. Viz DataFormats předdefinované formáty.

Návraty

Boolean

true pokud jsou data uložená v této instanci přidružena nebo lze převést na zadaný formát; jinak false.

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití GetDataPresent metody. Nejprve vytvoří datový objekt pomocí řetězce a Text formátu. Pak ověří, že data jsou ve Text formátu a zobrazí výsledky v poli se zprávou. V příkladu se předpokládá, že jste vytvořili pojmenovanou Form Form1.

private:
   void TestDataObject()
   {
      // Creates a new data object using a string and the Text format.
      String^ myString = "Hello World!";
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,myString );

      // Checks whether the data is present in the Text format and displays the result.
      if ( myDataObject->GetDataPresent( DataFormats::Text ) )
            MessageBox::Show( "The stored data is in the Text format.", "Test Result" );
      else
            MessageBox::Show( "The stored data is not in the Text format.", "Test Result" );
   }
       private void TestDataObject() 
       {
           // Creates a new data object using a string and the Text format.
           string myString = "Hello World!";
           DataObject myDataObject = new DataObject(DataFormats.Text, myString);

           // Checks whether the data is present in the Text format and displays the result.
           if (myDataObject.GetDataPresent(DataFormats.Text))
               MessageBox.Show("The stored data is in the Text format." , "Test Result");
           else
               MessageBox.Show("The stored data is not in the Text format.", "Test Result");
       }
Private Sub TestDataObject()
    ' Creates a new data object using a string and the Text format.
    Dim myString As New String("Hello World!")
    Dim myDataObject As New DataObject(DataFormats.Text, myString)

    ' Checks whether the data is present in the Text format and displays the result.
    If (myDataObject.GetDataPresent(DataFormats.Text)) Then
        MessageBox.Show("The stored data is in the Text format.", "Test Result")
    Else
        MessageBox.Show("The stored data is not in the Text format.", "Test Result")
    End If
End Sub

Poznámky

Voláním této metody určete, zda v tomto DataObject formátu existuje před voláním GetData. Volání GetFormats formátů, které jsou v této instanci k dispozici.

Poznámka

Data se dají převést do jiného formátu, pokud byla uložena, a pokud je požadovaný formát kompatibilní s uloženým formátem. Data uložená jako Unicode lze například převést na text.

Implementace této metody naleznete v tématu DataObject.GetDataPresent.

Viz také

Platí pro

GetDataPresent(Type)

Určuje, jestli jsou data uložená v této instanci přidružená nebo lze převést na zadaný formát.

public:
 bool GetDataPresent(Type ^ format);
public bool GetDataPresent (Type format);
abstract member GetDataPresent : Type -> bool
Public Function GetDataPresent (format As Type) As Boolean

Parametry

format
Type

Představuje Type formát, pro který se má zkontrolovat. Viz DataFormats předdefinované formáty.

Návraty

Boolean

true pokud jsou data uložená v této instanci přidružena nebo lze převést na zadaný formát; falsev opačném případě .

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití GetDataPresent metody. Nejprve vytvoří komponentu (myComponent) a uloží ji do datového objektu (myDataObject). Pak zkontroluje, zda jsou zadaná data uložena v myDataObject. Pokud se test vyhodnotí true, zobrazí výsledek v poli se zprávou a zobrazí datový typ v textovém poli. Tento příklad předpokládá, že jste již vytvořili pojmenovaný Form Form1 a pojmenovaný textBox1TextBox .

private:
   void GetDataPresent2()
   {
      // 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();

      // Checks whether the specified data type exists in the object.
      if ( myDataObject->GetDataPresent( myType ) )
      {
         MessageBox::Show( "The specified data is stored in the data object." );

         // Displays the type of data.
         textBox1->Text = "The data type is " + myDataObject->GetData( myType )->GetType()->Name + ".";
      }
      else
            MessageBox::Show( "The specified data is not stored in the data object." );
   }
       private void GetDataPresent2() 
       {
           // 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();

           // Checks whether the specified data type exists in the object.
           if (myDataObject.GetDataPresent(myType))
           {
               MessageBox.Show("The specified data is stored in the data object.");
               // Displays the type of data.
               textBox1.Text = "The data type is " + myDataObject.GetData(myType).GetType().Name + ".";
           }
           else
           {
               MessageBox.Show("The specified data is not stored in the data object.");
           }
       }
Private Sub GetDataPresent2()
    ' Creates a component to store in the data object.
    Dim myComponent As New System.ComponentModel.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()

    ' Checks whether the specified data type exists in the object.
    If myDataObject.GetDataPresent(myType) Then
        MessageBox.Show("The specified data is stored in the data object.")
        ' Displays the type of data.
        TextBox1.Text = "The data type is " & myDataObject.GetData(myType).GetType().Name & "."
    Else
        MessageBox.Show("The specified data is not stored in the data object.")
    End If
End Sub

Poznámky

Voláním této metody určete, zda v tomto DataObject formátu existuje před voláním GetData. Volání GetFormats formátů, které jsou v této instanci k dispozici.

Poznámka

Data se dají převést do jiného formátu, pokud byla uložena, a pokud je požadovaný formát kompatibilní s uloženým formátem. Data uložená jako Unicode lze například převést na text.

Implementace této metody naleznete v tématu DataObject.GetDataPresent.

Viz také

Platí pro

GetDataPresent(String, Boolean)

Určuje, zda jsou data uložená v této instanci přidružená k zadanému formátu pomocí logické hodnoty k určení, zda se mají data převést do formátu.

public:
 bool GetDataPresent(System::String ^ format, bool autoConvert);
public bool GetDataPresent (string format, bool autoConvert);
abstract member GetDataPresent : string * bool -> bool
Public Function GetDataPresent (format As String, autoConvert As Boolean) As Boolean

Parametry

format
String

Formát, pro který se má zkontrolovat. Viz DataFormats předdefinované formáty.

autoConvert
Boolean

true určit, zda lze data uložená v této instanci převést na zadaný formát; false zkontrolujte, jestli jsou data v zadaném formátu.

Návraty

Boolean

truepokud jsou data v nebo lze převést na zadaný formát; v opačném případě . false

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití GetDataPresent metody. Nejprve vytvoří datový objekt (myDataObject) pomocí řetězce a Text formátu. Pak dotazuje objekt na data přidružená Text k formátu s parametrem nastaveným autoConvert na false. Tato zkušební verze selže a výsledek se zobrazí v poli se zprávou s popiskem Zpráva #1. V druhé zkušební verzi nastaví autoConvert parametr na true. Tato zkušební verze bude úspěšná a výsledek se zobrazí v poli se zprávou s popiskem Zpráva #2. Příklad předpokládá, že jste vytvořili pojmenovanou Form Form1.

private:
   void GetDataPresent3()
   {
      // Creates a new data object using a string and the Text format.
      DataObject^ myDataObject = gcnew DataObject( DataFormats::Text,"My String" );

      // Checks whether the string can be displayed with autoConvert equal to false.
      if ( myDataObject->GetDataPresent( "System::String", false ) )
            MessageBox::Show( myDataObject->GetData( "System::String", false )->ToString(), "Message #1" );
      else
            MessageBox::Show( "Cannot convert data to the specified format with autoConvert set to false.", "Message #1" );

      // Displays the string with autoConvert equal to true.
      MessageBox::Show( "Now that autoConvert is true, you can convert " + myDataObject->GetData( "System::String", true ) + " to string format.", "Message #2" );
   }
       private void GetDataPresent3() 
       {
           // Creates a new data object using a string and the Text format.
           DataObject myDataObject = new DataObject(DataFormats.Text, "My String");

           // Checks whether the string can be displayed with autoConvert equal to false.
           if(myDataObject.GetDataPresent("System.String", false)) 
               MessageBox.Show(myDataObject.GetData("System.String", false).ToString(), "Message #1");
           else
               MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1");

           // Displays the string with autoConvert equal to true.
           MessageBox.Show("Now that autoConvert is true, you can convert " + 
               myDataObject.GetData("System.String", true).ToString() + " to string format.","Message #2");
       }
Private Sub GetDataPresent3()
    ' Creates a new data object using a string and the Text format.
    Dim myDataObject As New DataObject(DataFormats.Text, "My String")

    ' Checks whether the string can be displayed with autoConvert equal to false.
    If myDataObject.GetDataPresent("System.String", False) Then
        MessageBox.Show(myDataObject.GetData("System.String", False).ToString() + ".", "Message #1")
    Else
        MessageBox.Show("Cannot convert data to the specified format with autoConvert set to false.", "Message #1")
    End If
    ' Displays the string with autoConvert equal to true.
    MessageBox.Show(("Now that autoConvert is true, you can convert " + myDataObject.GetData("System.String", _
         True).ToString() + " to string format."), "Message #2")

End Sub

Poznámky

Voláním této metody určete, zda v tomto DataObject formátu existuje před voláním GetData. Volání GetFormats formátů dostupných v této instanci

Tato metoda vrátí true následující:

  • Parametr autoConvert je true a data jsou ve formátu, který lze převést na příslušný formát.

  • Parametr autoConvert je false a data jsou ve vhodném formátu.

Tato metoda vrátí false následující:

  • Parametr autoConvert je true a tato metoda nemůže najít data v zadaném formátu a nemůže převést data do zadaného formátu nebo byla uložena s nastavenou autoConvert hodnotou false.

  • Parametr autoConvert je falsea data v této instanci neexistují v zadaném formátu.

Poznámka

Data je možné převést do jiného formátu, pokud byla uložena určení, že převod je povolený, a pokud je požadovaný formát kompatibilní s uloženým formátem. Například data uložená jako Unicode se dají převést na text.

Implementace této metody naleznete v tématu DataObject.GetDataPresent.

Viz také

Platí pro