private void AddButton_Click(object sender, EventArgs e) { var productIDs = ProductGrid.SelectedRows.Cast <DataGridViewRow>() .Select(x => (int)x.Cells[ProductGrid_ID.Name].Value.AsInt()) .ToList(); using (var repository = new SaleRepository()) { repository.AddSaleItems(saleID, productIDs); repository.Commit(); } Close(); }