private void gridCategories_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex == colColor.Index) { var categoryModel = (CategoryModel)gridCategories.Rows[e.RowIndex].DataBoundItem; e.CellStyle.BackColor = !String.IsNullOrEmpty(categoryModel.Properties) ? DynamicCategoryProperties.FromJSON(categoryModel.Properties) .Background : Color.White; e.CellStyle.SelectionBackColor = e.CellStyle.BackColor; } } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }
private void gridCategories_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (!_triggeredByCtrl && e.RowIndex >= 0 && e.ColumnIndex == colColor.Index) { var gridRow = gridCategories.Rows[e.RowIndex]; var categoryModel = (CategoryModel)gridRow.DataBoundItem; var properties = !String.IsNullOrEmpty(categoryModel.Properties) ? DynamicCategoryProperties.FromJSON(categoryModel.Properties) : new DynamicCategoryProperties(); var dlg = new ColorDialog { Color = properties.Background }; if (dlg.ShowDialog(this) == DialogResult.OK) { properties.Background = dlg.Color; categoryModel.Properties = properties.ToJson(); var categoryRow = _views.MainForm.datasetMain.DynamicColumnCategories.FindByID(categoryModel.ID); if (categoryRow != null) { categoryRow.Properties = categoryModel.Properties; _views.MainForm.adapterDynamicColumnCategories.Update(categoryRow); } gridCategories.Refresh(); } } } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }