void NapSanPham() { DataTable dt = new DataTable(); bus = new BUS_SanPham(); dt = bus.selectdata(cboLoaiSP.SelectedValue.ToString()); dgv.DataSource = dt; if (dgv.ColumnCount > 0) { dgv.Columns[0].Visible = false; dgv.Columns[1].HeaderText = "Tên sản phẩm"; dgv.Columns[2].HeaderText = "Đơn vị"; dgv.Columns[3].HeaderText = "Đơn giá"; dgv.Columns[4].HeaderText = "Số tồn"; } for (int i = 0; i <= dgv.Columns.Count - 1; i++) { int colw = dgv.Columns[i].Width; dgv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgv.Columns[i].Width = colw; } dgv.RowsDefaultCellStyle.BackColor = Color.White; dgv.RowsDefaultCellStyle.SelectionBackColor = Color.CornflowerBlue; dgv.RowsDefaultCellStyle.SelectionForeColor = Color.White; dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.Plum; }
void NapLoaiSP() { cboLoaiSP.Items.Clear(); DataTable dt = new DataTable(); bus = new BUS_SanPham(); dt = bus.showdata(); var item = new Dictionary <string, string>(); foreach (DataRow dr in dt.Rows) { item.Add(dr["MaLoai"].ToString(), dr["TenLoai"].ToString()); } cboLoaiSP.DataSource = new BindingSource(item, null); cboLoaiSP.DisplayMember = "Value"; cboLoaiSP.ValueMember = "Key"; }