Back to Devexpress

How to: Show Array of Strings in ListBoxControl

windowsforms-9494-controls-and-libraries-editors-and-simple-controls-examples-how-to-show-array-of-strings-in-listboxcontrol.md

latest1.3 KB
Original Source

How to: Show Array of Strings in ListBoxControl

  • Oct 25, 2019

The code below uses an array of strings to populate the Items collection.

csharp
// Initialize an array of strings.
string[] myColors = {
                        Color.Black.Name,
                        Color.Blue.Name,
                        Color.Brown.Name,
                        Color.Green.Name,
                        Color.Red.Name,
                        Color.Yellow.Name,
                        Color.Orange.Name
                     };
// Check whether a data source is assigned to the ListBoxControl.
if (listBoxControl1.DataSource == null)
   // Add items to the ListBoxControl.
   listBoxControl1.Items.AddRange(myColors);
vb
' Initialize an array of strings.
Dim myColors() As String = New String() {Color.Black.Name, Color.Blue.Name, Color.Brown.Name, _
    Color.Green.Name, Color.Red.Name, Color.Yellow.Name, Color.Orange.Name}
' Check whether a data source is assigned to the ListBoxControl.
If ListBoxControl1.DataSource Is Nothing Then
   ' Add items to the ListBoxControl.
   ListBoxControl1.Items.AddRange(myColors)
End If