In a virtual grid, you normally do things dynamically in QueryCellInfo. If you want to color cells at this point based on changes your user makes to cell values, then I think you will have to cache the changed cells and their associated color, and then use this cache in QueryCellInfo to set the e.Style.BackColor when e.RowIndex and e.COlIndex point to one of your changed cells. For example, in CurrentCellChanging, you could test if you want to have a color assigned to the current cell that was changed. If so, create a key value using the CurrentCell.RowIndex and CurrentCell.ColIndex. Then add this key and the Color to a hashtable. Then in QueryCellInfo, use e.RowIndex and E.ColIndex to generate a key value, test if this keyvalue is on teh hashtable, and if so set e.Style.BackCOlor to the cached color.
Here are the changes I made to our VirtualGridTutorial sample to illustrate this idea.
private Hashtable savedColors = new Hashtable();
private Color lessColor = Color.Red;
private Color moreColor = Color.Green;
private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
int oldValue = (int)this.gridControl1[cc.RowIndex, cc.ColIndex].CellValue;
try
{
int newValue = int.Parse(cc.Renderer.ControlText);
if(newValue < oldValue)
{
int key = GetKey(cc.RowIndex, cc.ColIndex);
if (savedColors.ContainsKey(key))
savedColors[key] = lessColor;
else
savedColors.Add(key, lessColor);
}
else if(newValue > oldValue)
{
int key = GetKey(cc.RowIndex, cc.ColIndex);
if (savedColors.ContainsKey(key))
savedColors[key] = moreColor;
else
savedColors.Add(key, moreColor);
}
}
catch{}
}
private int GetKey(int row, int col)
{
return 100000 * col + row;
}
void GridQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
e.Style.CellValue = this._extData[e.RowIndex - 1, e.ColIndex - 1];
int key = GetKey(e.RowIndex, e.ColIndex);
if(savedColors.ContainsKey(key))
e.Style.BackColor = (Color) savedColors[key];
e.Handled = true;
}
}