Add Items to ListBox : ListBox « GUI Windows Forms « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / CSharp Tutorial » GUI Windows Forms » ListBox 
22. 27. 2. Add Items to ListBox
Add Items to ListBox
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class ListBoxItemAdd : System.Windows.Forms.Form
{
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.ListBox listBox1;

  private System.ComponentModel.Container components = null;

  public ListBoxItemAdd()
  {
    InitializeComponent();

  }

  protected override void Disposebool disposing )
  {
    ifdisposing )
    {
      if (components != null
      {
        components.Dispose();
      }
    }
    base.Disposedisposing );
  }

  private void InitializeComponent()
  {
    this.button1 = new System.Windows.Forms.Button();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.listBox1 = new System.Windows.Forms.ListBox();
    this.SuspendLayout();

    this.button1.Font = new System.Drawing.Font("Verdana"8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.button1.Location = new System.Drawing.Point(1616);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(8032);
    this.button1.TabIndex = 0;
    this.button1.Text = "Add";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // textBox1
    // 
    this.textBox1.AutoSize = false;
    this.textBox1.Location = new System.Drawing.Point(11216);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(16832);
    this.textBox1.TabIndex = 1;
    this.textBox1.Text = "textBox1";
    // 
    // listBox1
    // 
    this.listBox1.BackColor = System.Drawing.Color.Red;
    this.listBox1.ForeColor = System.Drawing.SystemColors.HighlightText;
    this.listBox1.Location = new System.Drawing.Point(864);
    this.listBox1.Name = "listBox1";
    this.listBox1.Size = new System.Drawing.Size(272238);
    this.listBox1.TabIndex = 2;
    // 
    // ListBoxItemAdd
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(328318);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.listBox1,
                                    this.textBox1,
                                    this.button1});
    this.Name = "ListBoxItemAdd";
    this.Text = "ListBoxItemAdd";
    this.ResumeLayout(false);

  }

  [STAThread]
  static void Main() 
  {
    Application.Run(new ListBoxItemAdd());
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
    listBox1.Items.Add(textBox1.Text);
  }
}
22. 27. ListBox
22. 27. 1. Set the TopIndex property of the ListBox to ensure the most recently added items are visibleSet the TopIndex property of the ListBox to ensure the most recently added items are visible
22. 27. 2. Add Items to ListBoxAdd Items to ListBox
22. 27. 3. Add ContextMenu to ListBoxAdd ContextMenu to ListBox
22. 27. 4. ListBox Items AddListBox Items Add
22. 27. 5. ListBox Items Add a RangeListBox Items Add a Range
22. 27. 6. ListBox Selection ModeListBox Selection Mode
22. 27. 7. Use RadioButton to control ListBox selection modeUse RadioButton to control ListBox selection mode
22. 27. 8. ListBox Events: SelectedIndexChanged, SelectedValueChanged, DataSourceChanged, DisplayMemberChanged, ValueMemberChanged
22. 27. 9. Add text in the TextBox to the ListBox
www__._ja_v__a__2__s_._com___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.