Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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);