Dictionary<RowColumnIndex, Color> colorDict = new Dictionary<RowColumnIndex, Color>();
void SetCellBackgroundColor(RowColumnIndex rowColumnIndex, Color color)
{
if (!colorDict.ContainsKey(rowColumnIndex))
colorDict.Add(rowColumnIndex, color);
else
colorDict[rowColumnIndex] = color;
sfDataGrid.TableControl.Invalidate(this.sfDataGrid.TableControl.GetCellRectangle(rowColumnIndex.RowIndex, rowColumnIndex.ColumnIndex, false));
}
this.sfDataGrid.QueryCellStyle += sfDataGrid_QueryCellStyle;
void sfDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e)
{
var rowColumnIndex = new RowColumnIndex(e.RowIndex,e.ColumnIndex);
if (colorDict.ContainsKey(rowColumnIndex))
e.Style.BackColor = colorDict[rowColumnIndex];
}
private void button1_Click(object sender, System.EventArgs e)
{
SetCellBackgroundColor(new RowColumnIndex(1, 0), Color.LightBlue);
}
|