Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
445
InitializeRow using saved appearance
posted

Hi

I have been looking at the WinGrid Performance guide and trying to implement some of the suggestions, particularly with regard to re-using appearances. In a grid layout event I set up a red forecolor appearance as follows:

private void ug_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
  // Set ForColor appearances for use later.

  if (e.Layout.Appearances.Exists("ForeColorRed") == false)
  {
    Infragistics.Win.Appearance redForeColour = e.Layout.Appearances.Add("ForeColorRed");       redForeColour.ForeColor = Color.Red;
  }
 
  // ....
}

In the initialize row event I test for a condition and apply font forecolor as follows:

private void ug_InitializeRow(object sender, InitializeRowEventArgs e)
{
  UltraGrid ug = sender as UltraGrid;
  UltraGridColumn structureNumberColumn = e.Row.Band.Columns["STRUCTURENUMBER"];
  int structureNumberValue = Convert.ToInt32(e.Row.GetCellValue(structureNumberColumn));
 
  if (structureNumberValue < 10)
  {
    e.Row.Appearance = ug.DisplayLayout.Appearances["ForeColorRed"];
  }
  else
  {
    e.Row.Appearance.ResetForeColor();
  }
 
  // ...
}

In this simplified case I want to set the row forecolor to red if the number value is < 10, otherwise use the default color. However, using ResetForeColor() appears to reset the forecolor for all rows in the grid (it's as if the saved appearance is destroyed the first time ResetForeColor() is called).

I can set another saved appearance such as 'ForeColorBlack' and that works fine but I just wanted to know if you can see anything wrong with my original approach because I can't figure out quite what's happening.

Regards

Adrian

Parents Reply Children
No Data