public List<SubItemLookUp> GetAllSubItemsForLookUp() { DBEgine objDbAccess = new DBEgine(); var list = new List<SubItemLookUp>(); try { objDbAccess.DBOpen(); SqlDataReader dr = objDbAccess.ExecuteReader("Inventory.GetAllSubItems", null); while (dr.Read()) { var subItem = new SubItemLookUp(); subItem.SubItemID = int.Parse(dr["SubItemID"].ToString()); subItem.SubItemSerial = dr["SubItemSerial"].ToString(); subItem.SubItemDescription = dr["SubItemDescription"].ToString(); subItem.SubItemUnitPrice = Convert.ToDecimal(dr["SubItemUnitPrice"].ToString()); list.Add(subItem); } return list; } catch (Exception ex) { throw ex; } finally { objDbAccess.DBClose(); } }
private void LoadSubItems(ComboBox comboBox) { var subItemList = new SubItemDAL().GetAllSubItemsForLookUp(); subItemList.ForEach(delegate(SubItemLookUp obj) { obj.SubItemDescription = obj.SubItemSerial + " - " + obj.SubItemDescription; }); var subItem = new SubItemLookUp(); subItem.SubItemDescription = "Select PLU"; subItem.SubItemID = -1; subItemList.Add(subItem); comboBox.DataSource = subItemList; comboBox.ValueMember = "SubItemID"; comboBox.DisplayMember = "SubItemDescription"; comboBox.SelectedValue = -1; }