Aracılığıyla paylaş


DomainUpDown.DomainUpDownItemCollection.Add(Object) Yöntem

Tanım

Belirtilen nesneyi koleksiyonun sonuna ekler.

public:
 override int Add(System::Object ^ item);
public override int Add (object item);
public override int Add (object? item);
override this.Add : obj -> int
Public Overrides Function Add (item As Object) As Integer

Parametreler

item
Object

Object koleksiyonun sonuna eklenecek.

Döndürülenler

Int32

Koleksiyona eklenen öğesinin Object sıfır tabanlı dizin değeri.

Örnekler

Aşağıdaki örnek bir DomainUpDown denetim oluşturur ve başlatır. Örnek, bazı özelliklerini ayarlamanıza ve yukarı aşağı denetimde görüntülenmek üzere bir dize koleksiyonu oluşturmanıza olanak tanır. Kod, formda bir TextBoxCheckBox ve örneğinin Button başlatıldığını varsayar. Örnekte ayrıca sınıf düzeyinde adlı myCounter32 bit imzalı tamsayı olarak bildirilen bir üye değişkeniniz olduğu varsayılır. Metin kutusuna bir dize girebilir ve düğmeye tıklandığında dizeyi koleksiyona Items ekleyebilirsiniz. Onay kutusuna tıklayarak özelliği değiştirebilir Sorted ve yukarı aşağı denetimdeki öğe koleksiyonundaki farkı gözlemleyebilirsiniz.

protected:
   DomainUpDown^ domainUpDown1;

private:
   void InitializeMyDomainUpDown()
   {
      // Create and initialize the DomainUpDown control.
      domainUpDown1 = gcnew DomainUpDown;
      
      // Add the DomainUpDown control to the form.
      Controls->Add( domainUpDown1 );
   }

   void button1_Click( Object^ sender,
      EventArgs^ e )
   {
      // Add the text box contents and initial location in the collection
      // to the DomainUpDown control.
      domainUpDown1->Items->Add( String::Concat(
         (textBox1->Text->Trim()), " - ", myCounter ) );
      
      // Increment the counter variable.
      myCounter = myCounter + 1;
      
      // Clear the TextBox.
      textBox1->Text = "";
   }

   void checkBox1_Click( Object^ sender,
      EventArgs^ e )
   {
      
      // If Sorted is set to true, set it to false; 
      // otherwise set it to true.
      domainUpDown1->Sorted =  !domainUpDown1->Sorted;
   }

   void domainUpDown1_SelectedItemChanged( Object^ sender,
      EventArgs^ e )
   {
      
      // Display the SelectedIndex and 
      // SelectedItem property values in a MessageBox.
      MessageBox::Show( String::Concat( "SelectedIndex: ", domainUpDown1->SelectedIndex,
         "\nSelectedItem: ", domainUpDown1->SelectedItem ) );
   }
protected DomainUpDown domainUpDown1;

private void InitializeMyDomainUpDown()
 {
    // Create and initialize the DomainUpDown control.
    domainUpDown1 = new DomainUpDown();
    
    // Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1);
 }
 
 private void button1_Click(Object sender, 
                           EventArgs e)
 {   
    // Add the text box contents and initial location in the collection
    // to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim()) + " - " + myCounter);
    
    // Increment the counter variable.
    myCounter = myCounter + 1;
 
    // Clear the TextBox.
    textBox1.Text = "";
 }
 
 private void checkBox1_Click(Object sender, 
                             EventArgs e)
 {
    // If Sorted is set to true, set it to false; 
    // otherwise set it to true.
    if (domainUpDown1.Sorted)
    {
       domainUpDown1.Sorted = false;
    }
    else
    {
       domainUpDown1.Sorted = true;
    }
 }
 
 private void domainUpDown1_SelectedItemChanged(Object sender, 
                                               EventArgs e)
 {
    // Display the SelectedIndex and 
    // SelectedItem property values in a MessageBox.
    MessageBox.Show("SelectedIndex: " + domainUpDown1.SelectedIndex.ToString() 
       + "\n" + "SelectedItem: " + domainUpDown1.SelectedItem.ToString());
 }
Protected domainUpDown1 As DomainUpDown


Private Sub InitializeMyDomainUpDown()
    ' Create and initialize the DomainUpDown control.
    domainUpDown1 = New DomainUpDown()
    
    ' Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1)
End Sub


Private Sub button1_Click(sender As Object, e As EventArgs)
    ' Add the text box contents and initial location in the collection
    ' to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter))
    
    ' Increment the counter variable.
    myCounter = myCounter + 1
    
    ' Clear the TextBox.
    textBox1.Text = ""
End Sub


Private Sub checkBox1_Click(sender As Object, e As EventArgs)
    ' If Sorted is set to true, set it to false; 
    ' otherwise set it to true.
    If domainUpDown1.Sorted Then
        domainUpDown1.Sorted = False
    Else
        domainUpDown1.Sorted = True
    End If
End Sub


Private Sub domainUpDown1_SelectedItemChanged _
    (sender As Object, e As EventArgs)
    
    ' Display the SelectedIndex and 
    ' SelectedItem property values in a MessageBox.
    MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _
        ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))
End Sub

Açıklamalar

Yöntemini kullanarak Insert koleksiyona yeni Object bir de ekleyebilirsiniz.

Daha önce eklemiş olduğunuz bir Object öğeyi Remove kaldırmak için veya RemoveAt yöntemlerini kullanın.

Şunlara uygulanır

Ayrıca bkz.