new 一个listitem
然后add进去就可以了

解决方案 »

  1.   

    用Add(object)来做:
    for (int i = 0; i< 100; i++)
    {
        this.listBox1.Items.Add("Item" + i.ToString());
    }
      

  2.   

    也可以绑定数据
    DataTable dt = new DataTable ( ) ;
    DataRow dr ;
    dt.Columns.Add ( new DataColumn ( "SocketId" , System.Type.GetType ( "System.Int32" ) ) ) ;
    Client objClient ;
    foreach ( DictionaryEntry d in mcolClients )
    {
    objClient = (Client) d.Value ;
    dr = dt.NewRow ( ) ;
    dr[0] = objClient.slaveId ;
    dt.Rows.Add ( dr ) ;
    }
    dt.DefaultView.Sort = "SocketId asc" ;
    chkListClient.DataSource = dt.DefaultView ;
    chkListClient.DisplayMember = "SocketId" ;
    chkListClient.ValueMember = "SocketId" ;
      

  3.   


    listBox1.Items.Add(要加的东西);
      

  4.   

    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());             
    }[JScript] 
    private function button1_Click(sender : Object, e : System.EventArgs)
    {
       // Create an instance of the ListBox.
       var listBox1 : ListBox = 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 (var x : int = 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());             
    }msdn 上的一个例子  希望能给你点参考。
      

  5.   

    ListBox listBox;
    listBox.Add(object);