private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { List <CategoryDTO> categories = categoryService.GetAllCategories(); foreach (var category in categories) { if (category.Name == comboBox1.Text) { List <GoodDTO> goods = goodService.GetByCategories(category.Id); var cartgoods = unitOfWork.Cartgoods.GetAll(); comboBox2.DataSource = goods; comboBox2.DisplayMember = "Name"; comboBox2.ValueMember = "Id"; comboBox2.SelectedIndexChanged += comboBox2_SelectedIndexChanged; foreach (var good in goods) { textBox1.Text = good.Price.ToString() + " uah"; foreach (var cartgood in cartgoods) { if (good.Id == cartgood.GoodId) { textBox2.Text = cartgood.Quantity.ToString(); } } } } } }