DomainUpDown.DomainUpDownItemCollection クラス

DomainUpDown クラスによって使用されるオブジェクトのコレクションをカプセル化します。

この型のすべてのメンバの一覧については、DomainUpDown.DomainUpDownItemCollection メンバ を参照してください。

System.Object
   System.Collections.ArrayList
      System.Windows.Forms.DomainUpDown.DomainUpDownItemCollection

Public Class DomainUpDown.DomainUpDownItemCollection
   Inherits ArrayList
[C#]
public class DomainUpDown.DomainUpDownItemCollection : ArrayList
[C++]
public __gc class DomainUpDown.DomainUpDownItemCollection : public
   ArrayList
[JScript]
public class DomainUpDown.DomainUpDownItemCollection extends
   ArrayList

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

DomainUpDown コントロールに表示するオブジェクトのコレクションを作成するには、 Add メソッドおよび Remove メソッドを使用して、項目を個別に追加または削除します。親コントロールである DomainUpDown で、 Items プロパティを使用して、コレクションにアクセスします。

使用例

[Visual Basic, C#, C++] DomainUpDown コントロールを作成し、初期化する例を次に示します。この例では、プロパティの一部を設定して、アップダウン コントロールに表示する文字列のコレクションを作成できます。このコードは、 TextBoxCheckBox 、および Button がフォーム上でインスタンス化されていることを前提にしています。この例は、 myCounter という名前の 32 ビット符号付き整数として宣言されたクラス レベルのメンバ変数があることも前提にしています。テキスト ボックスに文字列を入力すると、ボタンがクリックされたときにその文字列を Items コレクションに追加できます。チェック ボックスをクリックすると、 Sorted プロパティを切り替えて、アップダウン コントロール内の項目のコレクションの違いを確認できます。

 
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 'InitializeMyDomainUpDown


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 'button1_Click


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 'checkBox1_Click


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 'domainUpDown1_SelectedItemChanged

[C#] 
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());
 }


[C++] 
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);
 }
 
 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()), S" - ", __box(myCounter)));
    
    // Increment the counter variable.
    myCounter = myCounter + 1;
 
    // Clear the TextBox.
    textBox1->Text = S"";
 }
 
 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::Format( S"SelectedIndex: {0}\nSelectedItem: {1}",
       __box(domainUpDown1->SelectedIndex), domainUpDown1->SelectedItem ));
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

DomainUpDown.DomainUpDownItemCollection メンバ | System.Windows.Forms 名前空間 | Items