IDataObject.SetData Metoda

Definice

Uloží zadaná data a přidružený formát v této instanci.

Přetížení

Name Description
SetData(Object)

Uloží zadaná data v této instanci pomocí třídy dat pro formát.

SetData(String, Object)

Uloží zadaná data a přidružený formát v této instanci.

SetData(Type, Object)

Uloží zadaná data a jeho přidružený typ třídy v této instanci.

SetData(String, Boolean, Object)

Uloží zadaná data a přidružený formát v této instanci pomocí logické hodnoty k určení, zda lze data převést do jiného formátu.

SetData(Object)

Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs

Uloží zadaná data v této instanci pomocí třídy dat pro formát.

public:
 void SetData(System::Object ^ data);
public void SetData(object data);
public void SetData(object? data);
abstract member SetData : obj -> unit
Public Sub SetData (data As Object)

Parametry

data
Object

Data, která se mají uložit.

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití SetData metody. Nejprve vytvoří komponentu (myComponent) a uloží ji do datového objektu (myDataObject). Potom zkontroluje, jestli jsou zadaná data uložená v datovém objektu, a zobrazí výsledek v poli se zprávou. Příklad předpokládá, že jste vytvořili pojmenovaný FormForm1.

private:
   void SetData1()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the data object.
      myDataObject->SetData( myComponent );
      
      // Checks whether data of the specified type is in the data object.
      Type^ myType = myComponent->GetType();
      String^ myMessageText;
      if ( myDataObject->GetDataPresent( myType ) )
      {
         myMessageText = "Data of type " + myType->Name +
            " is present in the data object";
      }
      else
      {
         myMessageText = "Data of type " + myType->Name +
            " is not present in the data object";
      }
      
      // Displays the result in a message box.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData1() 
{
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a data object.
    DataObject myDataObject = new DataObject();

    // Adds the component to the data object.
    myDataObject.SetData(myComponent);
 
    // Checks whether data of the specified type is in the data object.
    Type myType = myComponent.GetType();
    string myMessageText;
    if(myDataObject.GetDataPresent(myType))
         myMessageText = "Data of type " + myType.Name + 
            " is present in the data object";
    else
        myMessageText = "Data of type " + myType.Name +
            " is not present in the data object";

    // Displays the result in a message box.
    MessageBox.Show(myMessageText, "The Test Result"); 
}
Private Sub SetData1()
   ' Creates a component to store in the data object.
   Dim myComponent As New System.ComponentModel.Component()
   
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Adds the component to the data object.
   myDataObject.SetData(myComponent)
   
   ' Checks whether data of the specified type is in the data object.
   Dim myType As Type = myComponent.GetType()
   Dim myMessageText As String
   If myDataObject.GetDataPresent(myType) Then
      myMessageText = "Data of type " + myType.Name + " is present in the data object"
   Else
      myMessageText = "Data of type " + myType.Name + " is not present in the data object"
   End If

   ' Displays the result in a message box.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Poznámky

Formát je odvozen z datové třídy.

Data uložená pomocí této metody lze při načtení převést do kompatibilního formátu.

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

Viz také

Platí pro

SetData(String, Object)

Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs

Uloží zadaná data a přidružený formát v této instanci.

public:
 void SetData(System::String ^ format, System::Object ^ data);
public void SetData(string format, object data);
public void SetData(string format, object? data);
abstract member SetData : string * obj -> unit
Public Sub SetData (format As String, data As Object)

Parametry

format
String

Formát přidružený k datům. Viz DataFormats předdefinované formáty.

data
Object

Data, která se mají uložit.

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití SetData metody. Nejprve vytvoří datový objekt (myDataObject) a uloží řetězec v objektu určujícím UnicodeText formát. Potom načte data uložená v objektu určující formát Text , aby se data převedli do Text formátu. Výsledek se zobrazí v poli se zprávou. Tento příklad předpokládá, že jste vytvořili pojmenovaný FormForm1.

private:
   void SetData2()
   {
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Stores a string, specifying the UnicodeText format.
      myDataObject->SetData( DataFormats::UnicodeText, "Hello World!" );
      
      // Retrieves the data by specifying the Text format.
      String^ myMessageText = "The data type is " +
         myDataObject->GetData( DataFormats::Text )->GetType()->Name;
      
      // Displays the result.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData2() 
{
    // Creates a data object.
    DataObject myDataObject = new DataObject();
 
    // Stores a string, specifying the UnicodeText format.
    myDataObject.SetData(DataFormats.UnicodeText, "Hello World!");
 
    // Retrieves the data by specifying the Text format.
    string myMessageText = "The data type is " + myDataObject.GetData(DataFormats.Text).GetType().Name;

    // Displays the result.
    MessageBox.Show(myMessageText, "The Test Result");
}
Private Sub SetData2()
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Stores a string, specifying the UnicodeText format.
   myDataObject.SetData(DataFormats.UnicodeText, "Hello World!")
   
   ' Retrieves the data by specifying the Text format.
   Dim myMessageText As String = "The data type is " & _
             myDataObject.GetData(DataFormats.Text).GetType().Name
   
   ' Displays the result.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Poznámky

Pokud neznáte formát cílové aplikace, můžete data ukládat ve více formátech pomocí této metody.

Data uložená pomocí této metody lze při načtení převést do kompatibilního formátu.

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

Viz také

Platí pro

SetData(Type, Object)

Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs

Uloží zadaná data a jeho přidružený typ třídy v této instanci.

public:
 void SetData(Type ^ format, System::Object ^ data);
public void SetData(Type format, object data);
public void SetData(Type format, object? data);
abstract member SetData : Type * obj -> unit
Public Sub SetData (format As Type, data As Object)

Parametry

format
Type

Představuje Type formát přidružený k datům. Viz DataFormats předdefinované formáty.

data
Object

Data, která se mají uložit.

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití SetData metody. Nejprve vytvoří komponentu (myComponent) a uloží ji do datového objektu (myDataObject), pomocí něhož myType určíte formát dat. Potom zkontroluje, zda jsou data zadaného typu uložena v objektu, a zobrazí výsledek v poli se zprávou. Příklad předpokládá, že jste vytvořili pojmenovaný FormForm1.

private:
   void SetData3()
   {
      // Creates a component.
      Component^ myComponent = gcnew Component;
      
      // Gets the type of the component.
      Type^ myType = myComponent->GetType();
      
      // Creates a data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Stores the component in the data object.
      myDataObject->SetData( myType, myComponent );
      
      // Checks whether data of the specified type is in the data object.
      String^ myMessageText;
      if ( myDataObject->GetDataPresent( myType ) )
      {
         myMessageText = "Data of type " + myType->Name +
            " is stored in the data object";
      }
      else
      {
         myMessageText = "No data of type " + myType->Name +
            " is stored in the data object";
      }
      
      // Displays the result.
      MessageBox::Show( myMessageText, "The Test Result" );
   }
private void SetData3() 
{
    // Creates a component.
    Component myComponent = new Component();
 
    // Gets the type of the component.
    Type myType = myComponent.GetType();
 
    // Creates a data object.
    DataObject myDataObject = new DataObject();
 
    // Stores the component in the data object.
    myDataObject.SetData(myType, myComponent);
 
    // Checks whether data of the specified type is in the data object.
    string myMessageText;
    if(myDataObject.GetDataPresent(myType))
        myMessageText = "Data of type " + myType.Name + 
            " is stored in the data object";
    else
        myMessageText = "No data of type " + myType.Name +
            " is stored in the data object";
            
    // Displays the result.
    MessageBox.Show(myMessageText, "The Test Result");
}
Private Sub SetData3()
   ' Creates a component.
   Dim myComponent As New System.ComponentModel.Component()
   
   ' Gets the type of the component.
   Dim myType As Type = myComponent.GetType()
   
   ' Creates a data object.
   Dim myDataObject As New DataObject()
   
   ' Stores the component in the data object.
   myDataObject.SetData(myType, myComponent)
   
   ' Checks whether data of the specified type is in the data object.
   Dim myMessageText As String
   If myDataObject.GetDataPresent(myType) Then
      myMessageText = "Data of type " & myType.Name & " is stored in the data object"
   Else
      myMessageText = "No data of type " & myType.Name & " is stored in the data object"
   End If
   
   ' Displays the result.
   MessageBox.Show(myMessageText, "The Test Result")
End Sub

Poznámky

Pokud neznáte formát cílové aplikace, můžete data ukládat ve více formátech pomocí této metody.

Data uložená pomocí této metody lze při načtení převést do kompatibilního formátu.

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

Viz také

Platí pro

SetData(String, Boolean, Object)

Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs
Zdroj:
IDataObject.cs

Uloží zadaná data a přidružený formát v této instanci pomocí logické hodnoty k určení, zda lze data převést do jiného formátu.

public:
 void SetData(System::String ^ format, bool autoConvert, System::Object ^ data);
public void SetData(string format, bool autoConvert, object data);
public void SetData(string format, bool autoConvert, object? data);
abstract member SetData : string * bool * obj -> unit
Public Sub SetData (format As String, autoConvert As Boolean, data As Object)

Parametry

format
String

Formát přidružený k datům. Viz DataFormats předdefinované formáty.

autoConvert
Boolean

trueaby byla data převedena do jiného formátu; v opačném případě . false

data
Object

Data, která se mají uložit.

Příklady

Tento příklad používá DataObject třídu, která implementuje IDataObject, demonstruje použití SetData metody. Nejprve vytvoří datový objekt (myDataObject) a uloží UnicodeText do něj řetězec s parametrem nastaveným autoConvert na false. Potom načte formáty přidružené k datům uloženým v objektu a zobrazí výsledek v poli se zprávou. Jediným formátem přidruženým k datům je UnicodeText formát. Tento příklad předpokládá, že jste vytvořili pojmenovaný FormForm1.

private:
   void SetData4()
   {
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;

      // Adds UnicodeText string to the object, and set the autoConvert
      // parameter to false.
      myDataObject->SetData( DataFormats::UnicodeText, false, "My text String*" );

      // Gets the data format(s) in the data object.
      array<String^>^arrayOfFormats = myDataObject->GetFormats();

      // Stores the results in a string.
      String^ theResult = "The format(s) associated with the data are: \n";
      for ( int i = 0; i < arrayOfFormats->Length; i++ )
         theResult = theResult + arrayOfFormats[ i ], " \n";

      // Show the results in a message box.
      MessageBox::Show( theResult );
   }
       private void SetData4() 
       {
           // Creates a new data object.
           DataObject myDataObject = new DataObject();

           // Adds UnicodeText string to the object, and set the autoConvert 
           // parameter to false.
           myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");

           // Gets the data format(s) in the data object.
           String[] arrayOfFormats = myDataObject.GetFormats();

           // Stores the results in a string.
           string theResult = "The format(s) associated with the data are:" + '\n';
           for(int i=0; i<arrayOfFormats.Length; i++)
               theResult += arrayOfFormats[i] + '\n';
           
           // Show the results in a message box. 
           MessageBox.Show(theResult);
       }
Private Sub SetData4()
    ' Creates a new data object.
    Dim myDataObject As New DataObject()

    ' Adds UnicodeText string to the object, and set the autoConvert
    ' parameter to false.
    myDataObject.SetData(DataFormats.UnicodeText, False, "My text string")

    ' Gets the data format(s) in the data object.
    Dim arrayOfFormats As [String]() = myDataObject.GetFormats()

    ' Stores the results in a string.
    Dim theResult As String = "The format(s) associated with the data are:" + _
            ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        theResult += arrayOfFormats(i) + ControlChars.Cr
    Next i
    ' Show the results in a message box. 
    MessageBox.Show(theResult)
End Sub

Poznámky

Pokud neznáte formát cílové aplikace, můžete data ukládat ve více formátech pomocí této metody.

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

Viz také

Platí pro