private void PopulateShippersComboBox() { NorthwindManager manager = new NorthwindManager(); var data = manager.ListShippers(); data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[select a shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; // Co Name is a property on shiper entity" cboShippers.ValueMember = "ShipperID"; // Shipper id is th property that repr primary key unique id //cboShippers.Items.Insert(0, "[select a shipper]"); cboShippers.SelectedIndex = 0; // first item in the combo box }
private void PopulateShippersComboBox() { NorthwindManager manager = new NorthwindManager(); var data = manager.ListShippers(); // Use a "fake" data item at the top of the list for the message data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[Select a Shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; // CompanyName is a property of the Shipper class cboShippers.ValueMember = "ShipperID"; // ShipperID is the property that represents the Primary Key cboShippers.SelectedIndex = 0; // the first item in the ComboBox }
private void PopulateShippersComboBox() { NorthwindManager nwm = new NorthwindManager(); var data = nwm.ListShippers(); data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[select a shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; cboShippers.ValueMember = "ShipperID"; //cboShippers.Items.Insert(0, "[select a shipper]"); cboShippers.SelectedIndex = 0; //the first in the cbo list }
private void PopulateShippersComboBox() { NorthwindManager manager = new NorthwindManager(); var data = manager.ListShippers(); //Use a 'fake' data item at top of list for the message data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[Select a Shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; cboShippers.ValueMember = "ShipperID"; //cboShippers.Items.Insert(0, "[Select a Shipper]"); cboShippers.SelectedIndex = 0; //first item in the combobox }
private void PopulateShippersComboBox() { NorthwindManager manager = new NorthwindManager(); var data = manager.ListShippers(); data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[Select a shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; // CompanyName is a property of the Shipper class cboShippers.ValueMember = "ShipperID"; // ShipperID is the property that represents the Primary Key (uniquely distinguishes each shipper in the database) //cboShippers.Items.Insert(0, "[Select a shipper]"); cboShippers.SelectedIndex = 0; }
private void ViewShippers_Load(object sender, EventArgs e) { // try and catch error NorthwindManager manager = new NorthwindManager(); var data = manager.ListShippers(); // use a fake data item at the top of list the messsage data.Insert(0, new Shipper() { ShipperID = -1, CompanyName = "[select a shipper]" }); cboShippers.DataSource = data; cboShippers.DisplayMember = "CompanyName"; // CompanyName is a property of // the Shipper class cboShippers.ValueMember = "ShipperID"; // ShipperID is the property that // represents the Primary key (uniquely distinguishes each shipper in the database) cboShippers.SelectedIndex = 0; // the first item in the combo box }