void SetBackOrTextColor(DataGridView gridView, int rowIndex, int columnIndex) { dlgColor.Color = ConditionalFormattingHelper.GetColorFromDisplayText((gridView.Rows[rowIndex].Cells[columnIndex]).Value.ToString()); if (dlgColor.ShowDialog() == DialogResult.Cancel) { return; } (gridView.Rows[rowIndex].Cells[columnIndex]).Value = ConditionalFormattingHelper.GetDisplayTextFromColor(dlgColor.Color); }
void btnSetDefaultSysDif_Click(object sender, EventArgs e) { for (int index = 0; index < dgvBaseSystemFormatting.Rows.Count; ++index) { dgvBaseSystemFormatting.Rows[index].Cells[colBackColorBaseSystemFormatting.Name].Value = ConditionalFormattingHelper.GetDisplayTextFromColor(_defaultColorSystemDifferences); dgvBaseSystemFormatting.Rows[index].Cells[colForeColorBaseSystemFormatting.Name].Value = ConditionalFormattingHelper._noSpecialColor; } }
internal ConditionalFormattingForm(string countryShortName, CountryConfigFacade countryConfigFacade) { InitializeComponent(); _countryConfigFacade = countryConfigFacade; lblCountry.Text = countryShortName; //put all systems in a list for easier access List <string> allSystemNames = new List <string>(); foreach (CountryConfig.SystemRow systemRow in countryConfigFacade.GetSystemRows()) { allSystemNames.Add(systemRow.Name); } //grid for format settings of base-derived-system differences: //add a row for each system (to be completed by base-system and format settings below, if there are any) //fill combo for selecting base system (with all available systems) foreach (string systemName in allSystemNames) { int index = dgvBaseSystemFormatting.Rows.Add(systemName, string.Empty, ConditionalFormattingHelper._noSpecialColor, ConditionalFormattingHelper._noSpecialColor); dgvBaseSystemFormatting.Rows[index].Cells[colBackColorBaseSystemFormatting.Name].Value = ConditionalFormattingHelper.GetDisplayTextFromColor(_defaultColorSystemDifferences); dgvBaseSystemFormatting.Rows[index].Tag = null; } foreach (CountryConfig.ConditionalFormatRow conditionalFormatRow in countryConfigFacade.GetConditionalFormatRows()) { //fill grid for format settings of conditional formatting if (conditionalFormatRow.Condition != null && conditionalFormatRow.Condition != string.Empty) { string applySystemNames = string.Empty; foreach (CountryConfig.ConditionalFormat_SystemsRow conditionalFormat_SystemsRow in conditionalFormatRow.GetConditionalFormat_SystemsRows()) { applySystemNames += conditionalFormat_SystemsRow.SystemName + _separator; } if (applySystemNames != string.Empty) { applySystemNames = applySystemNames.Substring(0, applySystemNames.Length - 1); } int index = dgvConditionalFormatting.Rows.Add(conditionalFormatRow.Condition, applySystemNames, conditionalFormatRow.BackColor == string.Empty ? ConditionalFormattingHelper._noSpecialColor : conditionalFormatRow.BackColor, conditionalFormatRow.ForeColor == string.Empty ? ConditionalFormattingHelper._noSpecialColor : conditionalFormatRow.ForeColor); dgvConditionalFormatting.Rows[index].Tag = conditionalFormatRow; } //complete grid for format settings of base-derived-system differences if (conditionalFormatRow.BaseSystemName != null && conditionalFormatRow.BaseSystemName != string.Empty) { if (countryConfigFacade.GetSystemRowByName(conditionalFormatRow.BaseSystemName) == null) { continue; //base system may have been deleted meanwhile } if (conditionalFormatRow.GetConditionalFormat_SystemsRows().Count() == 0) { continue; //should not happen, there ought to be either no or exactely one base-derived-differences setting (and if there is a setting there must be a respective system-format-link) } CountryConfig.ConditionalFormat_SystemsRow conditionalFormat_SystemsRow = conditionalFormatRow.GetConditionalFormat_SystemsRows().ElementAt(0); int index = allSystemNames.IndexOf(conditionalFormat_SystemsRow.SystemName); if (index < 0) { continue; //should not happen (would mean incomplete delete of a system or a similar error) } dgvBaseSystemFormatting.Rows[index].Cells[colBaseSystem.Name].Value = conditionalFormatRow.BaseSystemName; dgvBaseSystemFormatting.Rows[index].Cells[colBackColorBaseSystemFormatting.Name].Value = conditionalFormatRow.BackColor == string.Empty ? ConditionalFormattingHelper._noSpecialColor : conditionalFormatRow.BackColor; dgvBaseSystemFormatting.Rows[index].Cells[colForeColorBaseSystemFormatting.Name].Value = conditionalFormatRow.ForeColor == string.Empty ? ConditionalFormattingHelper._noSpecialColor : conditionalFormatRow.ForeColor; dgvBaseSystemFormatting.Rows[index].Tag = conditionalFormatRow; } } }