Paul Stovell gets development questions and he's not afraid to answer them. "I recieved an email this morning as from Steve Pietrek, a Delphi programmer moving to .NET (great choice Steve!). His question essentially asked how would he go about binding a Windows Forms ComboBox to an enumeration such as this:
public enum CustomerType {
Type1 = 1,
Type2 = 2,
Type3 = 3
}
Fortunately, I figured out how to do this in Trial Balance about a week ago, so I thought I’d share my approach here.
The values in an enumeration (Type1, Type2, Type3 in this
Every once in a while I need to bind an enumerated type to a Windows Forms control, usually a ComboBox. There are lots of articles here on The CodeProject that present various ways to do this, each with their own pros and cons. However, they are generally more complicated than necessary, and in some cases, require a lot of work on either the developer implementing the enum, the developer using it, or both.
The Simple Way
The simplest is to use the Enum.GetValues() method, setting its result to the DataSource property of the ComboBox. If you have the
Introduction
Every once in a while I need to bind an enumerated type to a Windows Forms control, usually a ComboBox. There are lots of articles here on The CodeProject that present various ways to do this, each with their own pros and cons. However, they are generally more complicated than necessary, and in some cases, require a lot of work on either the developer implementing the enum, the developer using it, or both.
The Simple Way
The simplest is to use the Enum.GetValues() method, setting its result to the DataSource property of the ComboBox.