2010-12-14 7 views
1

ListBoxオブジェクトを使用してC#でWindowsアプリケーションを作成するとします。私は購入するために6種類のものがある注文書を作成する必要があります。誰かが私にリストボックスをコード化する方法を教えてもらえますか?C#ListBoxアプリケーションの作成

+4

はこの宿題ですか? –

+0

私のクラスのためのその余分な信用 – user542672

+0

あなたはそれを撮影するのはいかがですか?どこかで立ち往生し、特定の "これがどうやって動かないの?"質問。 –

答えて

0

ListBox classをご覧ください。このMSDNページには多くの例があります。項目のリストを保持するItemsプロパティを見てください。

1

はおそらく、あなたはこのように、リストボックスを使用することができます"c# listbox tutorial"

1

のためのgoogle:

private void button1_Click(object sender, System.EventArgs e) 
{ 
    // Create an instance of the ListBox. 
    ListBox listBox1 = new ListBox(); 
    // Set the size and location of the ListBox. 
    listBox1.Size = new System.Drawing.Size(200, 100); 
    listBox1.Location = new System.Drawing.Point(10,10); 
    // Add the ListBox to the form. 
    this.Controls.Add(listBox1); 
    // Set the ListBox to display items in multiple columns. 
    listBox1.MultiColumn = true; 
    // Set the selection mode to multiple and extended. 
    listBox1.SelectionMode = SelectionMode.MultiExtended; 

    // Shutdown the painting of the ListBox as items are added. 
    listBox1.BeginUpdate(); 
    // Loop through and add 50 items to the ListBox. 
    for (int x = 1; x <= 50; x++) 
    { 
     listBox1.Items.Add("Item " + x.ToString()); 
    } 
    // Allow the ListBox to repaint and display the new items. 
    listBox1.EndUpdate(); 

    // Select three items from the ListBox. 
    listBox1.SetSelected(1, true); 
    listBox1.SetSelected(3, true); 
    listBox1.SetSelected(5, true); 

    // Display the second selected item in the ListBox to the console. 
    System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString()); 
    // Display the index of the first selected item in the ListBox. 
    System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());    
} 
関連する問題