private async void frmProduct_Load(object sender, EventArgs e) { RepositoryBrand repositoryBrand = new RepositoryBrand(); List <Brand> brands = await repositoryBrand.SelectAll(); List <BrandViewModel> brandViewModels = new List <BrandViewModel>(); foreach (Brand brand in brands) { BrandViewModel viewModel = new BrandViewModel { Id = brand.Id, Name = brand.Name }; brandViewModels.Add(viewModel); } cmbBrands.DataSource = brandViewModels; cmbBrands.DisplayMember = "Name"; cmbBrands.ValueMember = "Id"; cmbBrands.Refresh(); if (productToBeChanged != null) { txbProductName.Text = productToBeChanged.Name; cmbBrands.SelectedValue = productToBeChanged.BrandId; } else { txbProductName.Text = string.Empty; } }
private async void FillDataGridViewBrandsAsync() { IRepositoryGeneric <Brand> repositoryBrands = new RepositoryBrand(); List <Brand> brands = await repositoryBrands.SelectAll(); List <BrandViewModel> brandViewModels = new List <BrandViewModel>(); foreach (Brand brand in brands) { BrandViewModel viewModel = new BrandViewModel { Id = brand.Id, Name = brand.Name }; brandViewModels.Add(viewModel); } dgvBrands.Invoke((MethodInvoker) delegate { dgvBrands.DataSource = brandViewModels; dgvBrands.Refresh(); }); }