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
This article is pretty extensive with examples and links to more information. Here is a sample to address a common issue:
"Binding to a ComboBox or ListBox. This sample demonstrates binding data to a ComboBox. Binding data to a ListBox follows the same model.
To bind data to the list of items that are displayed, set the DataSource and DisplayMember properties of the ComboBox. The DisplayMember property is used to determine which property of the State object to display in the ComboBox. For example, the following code binds a ComboBox to an array of
There have been a lot of questions going around about XML and .Net Framework 2.0. Jesse Liberty attempts to answer some of them in his article on the subject: ".NET 2.0 pushes most of ADO.NET into the frameworks level, and provides you with various DataSource controls to make accessing data easy. With the XML DataSource control, you can bind to an XML document just as easily as you bind to tables in a database. If the XML document you load is hierarchical, the data is exposed hierarchically, which makes it ideal to map an XML document to a TreeView
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