Category Archives: lists

Display database records without data binding in C#

Many programs use data binding to display database records. That method is easy (at least as far as the code you write is concerned), but it’s not very flexible. This example shows how you can display database records without data … Continue reading

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

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

Make a list without duplicates in C#

This example builds a list of Person objects without duplicates. The following code shows the Person class. public class Person : IEquatable<Person> { public string FirstName, LastName; public Person(string first_name, string last_name) { FirstName = first_name; LastName = last_name; } … Continue reading

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

Move items between two ListBoxes in C#

One way to let the user select items from a list is to use a ListBox or a CheckedListBox. The user can Click, Ctrl+Click, Shift+Click, and user other keyboard and mouse combinations to select some of the items in the … Continue reading

Posted in controls, lists, user interface | 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

Initialize arrays, lists, and class instances in C#

You can initialize objects that implement IEnumerable such as arrays and lists by specifying items inside brackets and separated by commas. For example, the following code initializes an array of strings. // Arrays implement IEnumerable so this syntax works. string[] … Continue reading

Posted in arrays, classes, lists, OOP | Tagged , , , , , , , , , , , , , | 4 Comments

Determine whether two lists contain the same sequences of objects in different orders in C#

The SequenceEqual method determines whether two IEnumerable sequences contain the same objects in the same order. There is a simple way to determine whether the lists contain the same objects in different orders: sort the objects and then call SequenceEqual. … Continue reading

Posted in LINQ, lists, miscellany, OOP | Leave a comment

Determine whether two lists contain the same sequences of objects in C#

The IEnumerable interface provides a SequenceEqual method that determines whether two IEnumerable sequences contain the same objects. Normally it uses reference equality so it considers two objects equal only if they refer to the same instance. However, if the objects … Continue reading

Posted in lists, miscellany, OOP | 1 Comment

Access the keys and values stored in a Dictionary in C#

The Dictionary object provides a KeyCollection named Keys and a ValueCollection named Values to let you access the keys and values stored in the Dictionary. These collections are slightly different from the List objects that you probably use in your … Continue reading

Posted in controls, lists | Leave a comment