private void FillCompanyList() { using (MedicalDBEntityModelConnection context = new MedicalDBEntityModelConnection()) { var companyList = context.GET_Companies().ToList(); if (companyList.Count > 0) { dgCompanyList.DataSource = companyList; dgCompanyList.Columns[0].Visible = false; dgCompanyList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); Dictionary <string, string> item = new Dictionary <string, string>(); foreach (var c in companyList) { item.Add(c.Id.ToString(), c.CompanyName); } cmbCompanies.DataSource = new BindingSource(item, null); cmbCompanies.DisplayMember = "Value"; cmbCompanies.ValueMember = "Key"; } else { cmbCompanies.DataSource = null; dgCompanyList.DataSource = null; } } }
private void FillCompanyList() { using (MedicalDBEntityModelConnection context = new MedicalDBEntityModelConnection()) { var companyList = context.GET_Companies().ToList(); if (companyList.Count > 0) { Dictionary <string, string> item = new Dictionary <string, string>(); foreach (var c in companyList) { item.Add(c.Id.ToString(), c.CompanyName); } cmbCompanies.DataSource = new BindingSource(item, null); cmbCompanies.DisplayMember = "Value"; cmbCompanies.ValueMember = "Key"; } else { dgViewStock.DataSource = null; cmbCompanies.DataSource = null; MessageBox.Show(Constants.COMPANY_NONE); } } }