ListBox Control.
The System.Windows.Forms.ListBox control enabled you to display a list of items
from which the user can select one or multiple items from the list. The default
is for the ListBox to list the items vertically however setting the multicolumn
property to true the items are listed horizontally. The control is typically used
to display data from a database. The items listed within the ListBox cannot be edited
directly.

Namespace: System.Windows.Forms
Assembly: Systems.Windows.Forms.dll
using System.Windows.Forms;
Calling: System.Windows.Forms.ListBox
Creating a new System.Windows.Forms.ListBox control.
ListBox listBox1 = new ListBox();
Adding the ListBox control to a Windows form.
this.Controls.Add(listBox1);
Placing the ListBox on the form at a specific location.
listBox1.Location = new Point(50, 50);
Assigning a text value to a ListBox control.
listBox1.Text = "Enter";
Assigning a listBox1_SelectedIndexChanged event to the button control.
listBox1.SelectedIndexChanged+=new EventHandler(listBox1_SelectedIndexChanged);
Responding to the ListBox SelectedIndexChanged event.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//The MessageBox is part of the System.Windows.Forms namespace.
MessageBox.Show(listBox1.SelectedItem.ToString());
}
Changing the background color of the ListBox control.
listBox1.BackColor = System.Drawing.Color.Red;
To disable the button control.
listBox1.Enabled = false;
Here the ListBox control is still visible (partially faded) but will not respond
to any events. To re-enable the ListBox control you would set the Enabled property
to true. When adding the ListBox control the default setting is for the control
to be Enabled.
With the ListBox control, you can add many different types of objects or classes.
The control can be bound to a data source to present data from a database to the
end user.
The Infragistics control set does not include the listbox control. You can sort
of use the UltraTree view control and set the boolean property FullRowSelect to
true. This will only give you the look of the ListBox control but you do not have
the important control events.
Rather use the System.Windows.Forms.ListBox or another .net third party control.
|