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.
I still have not figured out the issue, but I think I am going to have another problem once this is resolved. I can't figure out how to "base" a new appearance off of an existing one. I want the grid's surrent SelectedAppearance and appearance for the cells to remain the same and just change the color of the text to red. When I create a new appearance and change the ForeColor to red I get strange results. I am guessing because the other appearance settings are lost on this new one.
Is there any way to access the app stylist information in code, or another way to base a new appearance on an existing one?