private void AddButton_Click(object sender, EventArgs e) { var componentIDs = ComponentGrid.SelectedRows.Cast <DataGridViewRow>() .Select(x => (int)x.Cells[ComponentGrid_ID.Name].Value.AsInt()) .ToList(); using (var repository = new SupplyRepository()) { repository.AddSupplyItems(supplyID, componentIDs); repository.Commit(); } Close(); }