private void LoadStateComboBox() { List <State> states = new List <State>(); try { states = StateDB.GetStates(); cboStates.DataSource = states; cboStates.DisplayMember = "StateName"; cboStates.ValueMember = "StateCode"; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void LoadStateComboBox() { // create new List of States List <State> states = new List <State>(); try { // get states from the state database states = StateDB.GetStates(); cboStates.DataSource = states; // what you want the user to see: state name cboStates.DisplayMember = "StateName"; // what field you want in the database: state code cboStates.ValueMember = "StateCode"; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }