public static bool ChooseLabel(List <Rom> roms, out List <RomLabel> selectedLabels, out List <RomLabel> unselectedLabels) { selectedLabels = new List <RomLabel>(); unselectedLabels = new List <RomLabel>(); instance = new FormChooseList(typeof(RomLabel)); foreach (DataGridViewRow row in instance.dataGridView.Rows) { row.Cells[instance.columnCheck.Index].Value = CheckState.Unchecked; bool found = false; bool all = false; bool checkFound = false; bool notFound = false; string labelName = row.Cells[instance.columnName.Index].Value.ToString(); foreach (var rom in roms) { checkFound = rom.RomLabels != null && rom.RomLabels.Labels.Any(x => x == labelName); if (checkFound) { found = true; } else { notFound = true; } } all = found && !notFound; if (found && all) { row.Cells[instance.columnCheck.Index].Value = CheckState.Checked; } else if (!found) { row.Cells[instance.columnCheck.Index].Value = CheckState.Unchecked; } else if (found && !all) { row.Cells[instance.columnCheck.Index].Value = CheckState.Indeterminate; } found = false; all = false; } var result = instance.ShowDialogUpdated(); selectedLabels = instance.selectedLabels; unselectedLabels = instance.unselectedLabels; return(result); }
private void changeLabelsToolStripMenuItem_Click(object sender, EventArgs e) { try { if (dataGridView.SelectedRows.Count == 0) { return; } List <RomLabel> selectedLabels = new List <RomLabel>(); List <RomLabel> unselectedLabels = new List <RomLabel>(); RomLabels labels = ((Rom)dataGridView.SelectedRows[0].Tag).RomLabels; List <Rom> roms = new List <Rom>(); foreach (DataGridViewRow row in dataGridView.SelectedRows) { roms.Add((Rom)row.Tag); } if (!FormChooseList.ChooseLabel(roms, out selectedLabels, out unselectedLabels)) { return; } RomLabelsBusiness.SetRomLabel(roms, selectedLabels, unselectedLabels); foreach (DataGridViewRow row in dataGridView.SelectedRows) { FillLabelCell((Rom)row.Tag, row); } dataGridView.Refresh(); } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }