public void LoadProducts() { listProducts = productModel.getProductsToSale(); DataTable dtProduct = ConvertCustom.ListToDataTable <TblProductsDTO>(listProducts); bsProduct = new BindingSource() { DataSource = dtProduct }; //binding data to data grid view form.getBnProduct().BindingSource = bsProduct; form.getDgvProduct().DataSource = bsProduct; //hide unessesary column form.getDgvProduct().Columns["idProduct"].Visible = false; form.getDgvProduct().Columns["status"].Visible = false; form.getDgvProduct().Columns["idCategory"].Visible = false; form.getDgvProduct().Columns["categoryName"].Visible = false; List <TblCategoryDTO> listCategory = categoryModel.getAll(); foreach (var category in listCategory) { form.getCmbCategory().Items.Add(category.name); } foreach (DataGridViewColumn column in form.getDgvProduct().Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } }
public void getAllCategory() { try { List <TblCategoryDTO> categoryDTOs = categoryModel.getAll(); DataTable dataTable = ConvertCustom.ListToDataTable(categoryDTOs); bindingSourceCategory = new BindingSource() { DataSource = dataTable }; form.GetDataGridViewCategory().DataSource = bindingSourceCategory; form.GetDataGridViewCategory().Columns["idCategory"].Visible = false; form.GetBindingNavigatorCategory().BindingSource = bindingSourceCategory; clearDataBindingTextCategory(); bindingDataTextCategory(); } catch (Exception e) { MessageBox.Show(MessageUtil.ERROR + " Get All Category"); } }