Tag Archives: ListBox

Initialize lists from databases without binding in C#

Note that this is a very manual way to initialize lists. Often you can display data more easily by using data binding. In this example, I added the Access database file Books.mdb to the project and set its “Copy to … Continue reading

Posted in controls, database, lists, user interface | Tagged , , , , , , , , , , , , | 1 Comment

Display tooltips for ListView items in C#

This example shows how to display different tooltips for the items in a ListBox. When you move the mouse over an item in the ListBox, the program uses the following code to display a tooltip for it. // Display a … Continue reading

Posted in controls | Tagged , , , , , , , , , , , , | 3 Comments

Sort partly numeric items in a ComboBox or ListBox in C#

The example Use a custom sort order for ListBox or ComboBox items in C# shows how to sort numeric values. This example uses the same basic approach: make an array of values, sort them as you want them displayed, and … Continue reading

Posted in algorithms, controls | Tagged , , , , , , , , , , , | 1 Comment

Display the number of checked items in a CheckedListBox in C#

The CheckedListBox control has a CheckedItems collection that holds references to the control’s currently checked items. You can use the collection’s Count property to determine the number of items checked. When the user checks or unchecks an item, the control … Continue reading

Posted in controls, lists | Tagged , , , , , , , , , , , | Leave a comment

Use a custom sort order for ListBox or ComboBox items in C#

If you set a ComboBox and ListBox control’s Sorted property to true, the control sorts the items it contains. Unfortunately it sorts the items alphabetically. That means if the items are strings that begin with Roman numerals, they may be … Continue reading

Posted in algorithms, controls, user interface | Tagged , , , , , , , , , , , , , , , | 2 Comments

Sort ListBox or ComboBox items in numeric order in C#

If you set a ListBox control’s Sorted property to true, the control sorts its contents. Unfortunately it can only sort its contents in alphabetic order. If the items are numeric, that may not be what you want. This example sorts … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | Leave a comment

List colors in WPF and C#

This example shows how to list colors and display color samples in a WPF ListBox. To build the list, the example demonstrates reflection, LINQ, and XAML data templates. The program uses the following XAML code to define the ListBox that … Continue reading

Posted in drawing, enums, graphics, LINQ, reflection, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Bind arrays and lists in C#

One way to display the items in an array in a ListBox is to loop through the items and add them to the ListBox one at a time, but there’s an easier way. You can bind arrays to a ListBox … Continue reading

Posted in arrays, controls, lists | Tagged , , , , , , , , , , , , | 2 Comments

Make an owner-drawn ListBox with pictures in C#

This example extends the previous one Make an owner-drawn ListBox in C# to make an owner-drawn ListBox with pictures. The program uses the following Planet class to represent information about the planets. class Planet { public string Name = “”; … Continue reading

Posted in controls, graphics | Tagged , , , , , , , , , , , | 5 Comments

Select ComboBox or ListBox values that contain target text in C#

The List timezones in C# example fills a ComboBox with a list of timezones. I would like to select an initial value based on the text in the items, but I don’t want to have to select the exact text, … Continue reading

Posted in controls, interfaces | Tagged , , , , , , , , , , , , , , | 2 Comments