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
490
Reusing Appearance object
posted

Hi,

I am getting an error of "Key already exists" when trying to reuse an appearance object with the UltraGrid.  Here is the scenario:

1. In the grid's Initialize_Layout method I have the following code to set up my appearance:

 

// cancel date appearance

if (!this.ugCommon.DisplayLayout.Appearances.Exists(CANCEL_DATE))

{

Infragistics.Win.Appearance cancelDateAppearance = this.ugCommon.DisplayLayout.Appearances.Add(CANCEL_DATE);

cancelDateAppearance.ForeColor = Color.Red;

}

2. My grid has a column called "Cancel Date".  If today's date is greater than this value then I need to make the text of the entire row red.  To do this I added some code to the InitializeRow event.  I compare the dates and if I have to add the red coloring I am doing this:


foreach (UltraGridCell c in e.Row.Cells)

{

c.SelectedAppearance = this.ugCommon.DisplayLayout.Appearances[CANCEL_DATE];

c.Appearance = this.ugCommon.DisplayLayout.Appearances[CANCEL_DATE]; <== Problem Line of Code

}

The error occurs on the second line in the foreach loop:


c.Appearance = this.ugCommon.DisplayLayout.Appearances[CANCEL_DATE];

I am not sure what is going on here.  I have to make sure both the appearance and the selected appearance have red text, so I need to change both.