|
sfDataGrid1.QueryRowStyle += SfDataGrid1_QueryRowStyle;
Dictionary<RowColumnIndex, Color> colorDict = new Dictionary<RowColumnIndex, Color>();
private void SfDataGrid1_QueryRowStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryRowStyleEventArgs e)
{
var rowColumnIndex = new RowColumnIndex(e.RowIndex,0);
if (colorDict.ContainsKey(rowColumnIndex))
e.Style.BackColor = colorDict[rowColumnIndex];
}
void SetCellBackgroundColor(RowColumnIndex rowColumnIndex, Color color)
{
if (!colorDict.ContainsKey(rowColumnIndex))
colorDict.Add(rowColumnIndex, color);
else
colorDict[rowColumnIndex] = color;
}
private void sfButton2_Click(object sender, EventArgs e)
{
foreach (var selectedItem in sfDataGrid1.SelectedItems)
{
var index = sfDataGrid1.TableControl.ResolveToRowIndex(selectedItem);
SetCellBackgroundColor(new RowColumnIndex(index, 0), Color.Green);
}
} |