windowsforms-9493-controls-and-libraries-editors-and-simple-controls-examples-how-to-create-listboxcontrol-at-runtime.md
The following sample code demonstrates how to initialize and create a new instance of the ListBoxControl class at runtime.
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);
Imports DevExpress.XtraEditors
' ...
' Initialize an array of strings
Dim States() As String = New String() {"Alabama", "Alaska", "Arizona", "California", _
"Colorado", "Florida", "Idaho", "Kansas", "Michigan", "Nevada", "Texas", "Utah"}
' Initialize and create an instance of the ListBoxControl class
Dim listBox As New ListBoxControl()
' Define the parent control
listBox.Parent = Me
' 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)