// description of your code here
// insert code here..
Bind a ComboBox to an array of State objects
namespace Akadia.ComboBoxBinding
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class ComboBoxBinding : System.Windows.Forms.Form
{
.....
// Lookup "Table" with States for the Comobox
public struct State
{
private string _shortName, _longName;
public State(string longName , string shortName)
{
this._shortName = shortName;
this._longName = longName;
}
public string ShortName { get { return _shortName; } }
public string LongName { get { return _longName; } }
}
// Define the Array of States for the DropDown List
public State[] States = new State[] {
new State("Alabama","AL")
,new State("Alaska","AK")
,new State("Arizona" ,"AZ")
,new State("Arkansas","AR")
,new State("California" ,"CA")
......
} ;
public ComboBoxBinding()
{
.......
// Populate the list
comboBoxState.DataSource = States;
// Define the field to be displayed
comboBoxState.DisplayMember = "LongName";
// Define the field to be used as the value
comboBoxState.ValueMember = "ShortName";
// Bind the selected value of the the ComboBox to the
// Region field of the current Customer
comboBoxState.DataBindings.Add("SelectedValue", customersDataSet1, "Customers.Region");
........
}
}
}