I would like to have 2 different colors for the alternate row color in one grid (only 1 band).
For rows of type X I use the value assigned to :
this.ultraGrid1.DisplayLayout.Override.RowAlternateAppearance.BackColor
But for rows of type Y I am trying to override this using the initialize row event...I try to do this
// first test for type Y row...if (row.IsAlternate)
{ row.Appearance.BackColor = Color.Green; }
However, when I view the results, the type Y rows do not alternate, they clump up in 2, 3 or more green rows in sequence.
Is there anything I am doing wrong here?
Hi,
My guess is that a row may be changing to and from an alternate at various staging of your application. For example, if you filter or sort the rows the some rows will become alternates and some that were alternates will become non-alternates. It's this latter group that is the problem, since the code you posted here never resets the appearance on the non-alternate rows.
You probably just need to add an else block and reset the row appearance for rows that are not alternates.
That makes sense, but unfortunately it did not work. I still get the uneven distribution of green rows.
FWIW, the collection of rows in the datasource is all built before the grid is displayed. This is not a problem with rows being inserted at runtime.
If you insert a row, then you have to refresh all of the other rows in the list. So any time you do anything that will change the IsAlternate state of a row, you will have to call grid.Rows.Refresh(FireInitializeRow) so that all of the rows get their new colors.
I made the change, and now rows are displayed correctly after sorting changes. But inserted rows are not. Is there a simple/efficient way to reset the alternating colors on each row, without updating each row in sequence (I am concerned about the performance implications here).
Actually I got it to work by sorting the datasource collection to match the default column sort before rendering the grid. That works initially, but if the sort changes or a new row is inserted, then it breaks again.
I will try adding an
if (row.IsAlternate == false) check to always color the row background regardless...but I am skeptical that will resolve the sort or insert issue. I would rather not have to reset each rows background manually each time a row is modified or inserted....there could be 1000+ rows and I am concerned about the performance - is there any other way to handle this?
Upon further reflection, simply adding an 'else' block to the code you have here won't work, because you are still inside the 'if' which checks your other condition. You need to reset the appearance on the row regardless of whether it meets the condition or is an alternate.
Basically, you should always be doing something to the row inside InitializeRow - either apply an appearance or reset it.
If that's still not working, them the only other things that makes sense is that maybe you are hiding or filtering some rows and this process is not causing InitializeLayout to re-fire for rows that are already initialized. If that's the case, then all you have to do is find where you are setting the sort, filter, or hide and call grid.Rows.Refresh(FireInitializeRow) to force the rows to get re-initialized.