O'Reilly logo

Developer’s Guide to Collections in Microsoft® .NET by Calvin “Lee” Janes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Using Collections with Windows Form Controls

After completing this chapter, you will be able to

  • Perform simple bindings with the controls.

  • Create two-way bindings with the controls.

  • Understand the sample code.

Simple Binding

Some Windows Form controls can bind to collections that implement IList and IEnumerable by setting the DataSource property of the ListBox, ComboBox, or DataGridView classes to the collection; the following shows an example.

C#

ListBox lb = new ListBox();

lb.DataSource = new int [] { 1,2,3,4,5 };

Visual Basic

Dim lb As New ListBox()

lb.DataSource = New Integer() {1, 2, 3, 4, 5}

To control which property of the items in the collection these controls should display, you set the DisplayMember property of the ComboBox or ListBox ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required