Hello,
Using v9.2, UltraWinGrid
Can rows be alternatively colored based on value of a column ? for example by category in table below, I tried to do it mannually but when i changed the AppStyle the color I set was not visible, so seems like the coloring only works some styles.
Is there any best way of doing this ?
Thanks in advance for any help.
Shekhar
Thanks Mike, for the support.
ShekharAvionte said:My first question, is there a better way of coloring the rows based on the value of the cell ?
Typically, you would use the InitializeRow event, if you just want to color a row or cell based on the contents. But in this case, it seems like you need to color the row not just based on it's own contents, but the contents of the adjacent rows. So you are probably better off looping through the rows - assuming you have a small number of rows.
ShekharAvionte said:Secondly, The coloring of rows as above only works for the AppStyles/theme with lighter background, and Color.LightGray is not visible on the styles with darker background. How can we color relatively to Styles ?
What I would do is add a Resource to the isl file that has the appearance(s) you need. Then you can use the row.Appearance.StyleResourceName property to apply that resource to the row. This way the appearance is defined in each isl file, rather than in your application, which won't know about the colors used by the isl.
Sorry Mike for the confusion,
If row1 and row2 are two consecutive rows, we've used the following logic to set the backColor for all of the rows in the grid
if (row1.Cells["Category"].Value.ToString() != row1.Cells["Category"].Value.ToString()) { row2.Appearance.BackColor = row1.Appearance.BackColor == Color.Empty ? Color.LightGray : Color.Empty; }
My first question, is there a better way of coloring the rows based on the value of the cell ? there is a property RowAlternateAppearance which determines the appearance of alternate rows(I guess based on the row numbers being odd or even) but in this case as we can see the rows are identified as alternate according to the "Category" values not odd or even rows.
Secondly, The coloring of rows as above only works for the AppStyles/theme with lighter background, and Color.LightGray is not visible on the styles with darker background. How can we color relatively to Styles ?
Thanks
Hi,
I don't understand your question. What are you trying to do and what does AppStylist have to do with it?
It sounds to me like you need to use the InitializeRow event for what you want - if you are trying to base the color of the row both on the value of a cell and on whether that row is odd or even.