Skip to main content

How to: Create ListBoxControl at Runtime

The following sample code demonstrates how to initialize and create a new instance of the ListBoxControl class at runtime.

ListBoxControl-ctor

using DevExpress.XtraEditors;
// ...
// Initialize an array of strings
string[] States = {
                     "Alabama",
                     "Alaska",
                     "Arizona",
                     "California",
                     "Colorado",
                     "Florida",
                     "Idaho",
                     "Kansas",
                     "Michigan",
                     "Nevada",
                     "Texas",
                     "Utah"
                  };
// Initialize and create an instance of the ListBoxControl class
ListBoxControl listBox = new ListBoxControl();
// Define the parent control
listBox.Parent = this;
// Set the listBox's background color
listBox.BackColor = Color.FromArgb(254, 246, 212);
// Dock to all edges and fill the parent container
listBox.Dock = DockStyle.Fill;
// Add items
listBox.Items.AddRange(States);