DomainUpDown.DomainUpDownItemCollection.Add(Object) Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Добавляет указанный объект в конец коллекции.
public:
override int Add(System::Object ^ item);
public override int Add(object item);
override this.Add : obj -> int
Public Overrides Function Add (item As Object) As Integer
Параметры
Возвращаемое значение
Отсчитываемое от нуля значение Object индекса, добавленного в коллекцию.
Примеры
В следующем примере создается и инициализируется DomainUpDown элемент управления. В этом примере можно задать некоторые из его свойств и создать коллекцию строк для отображения в элементе управления "Вверх". В коде предполагается, что экземпляр TextBoxCheckBox объекта и Button экземпляр был создан в форме. В примере также предполагается, что у вас есть переменная-член на уровне класса, объявленная как 32-разрядное целое число со знаком с именем myCounter. Вы можете ввести строку в текстовом поле и добавить ее Items в коллекцию при нажатии кнопки. Щелкнув флажок, вы можете переключать Sorted свойство и наблюдать за разницей в коллекции элементов в элементе управления вверх.
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
Комментарии
Вы также можете добавить новую Object в коллекцию Insert с помощью метода.
Чтобы удалить добавленное Object ранее значение, используйте Remove методы или RemoveAt методы.