If I have certain rows that I want to change the font color, while the whole UltraGrid is using a style library, how do I do that? I tried to set the CellAppearance.ForeColor to that row, but it didn't change. How do I overwrite Stylelibrary settings for a specific row?
Thanks.
Richard Zhu
Hi Richard,
AppStylist shouldn't be overriding the appearance properties for an individual row or cell. Exactly what object are you setting the CellAppearance of?
Just as a test, I tried loading pear.isl into a project with a grid and using the following code:
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row.Index % 2 == 0) { e.Row.CellAppearance.ForeColor = Color.Red; } }
This worked fine for me and every even-numbered row in the grid showed up red.
Hi, Mike
I just figured out some more detail. I was using exactly the same code as you used in the example, setting CellAppearance.ForeColor of selected row. However, some fields in the row are not displayed in red. Turned out, the 3 columns that does not take the Red color all have their DataType set to typeof(bool), even though on display the values are either "Yes" or "No". Now my question is this: How is the ForeColor configured for a Boolean column? How do I change it. I found that if I specifically set the Cell.Appearance.ForeColor to red, these 3 columns will display red. But since I've already set CellAppearance for the row, I'd like to have a more general solution.
Thanks in advance.
rzhu said:Is there a way programatically to determine the final resulted ForeColor of a cell, after the overlapping of all layers that sets the property?
No.
rzhu said:Even further, is there a way to find out which layer the final value comes from?
The good news is now that I know you're using a ValueList, I have a pretty good guess about what's going on. :)
My guess is that your application style library is applying a ForeColor to the ValueListItem UIRole. What happens is that when you have a ValueList in the grid and you select an item from the list, the cell picks up the appearance of that item. This makes sense if your items are all differnent colors or if they have images.
In this case, however, it doesn't make sense to use this UIRole in AppStylist. The style library is probably using this role to provide an appearance for every ValueListItem. But this is not a good way to do it, since this will affect the grid cells, as well. So the thing to do is to open up your style library and take a look at the ValueListItem UIRole. It's a direct descendant of the Base role and it's the last one on the list, so it's easy to find. Reset this role and see if that fixes the issue. If it does, and you still have to color the ValueListItems, you can apply the same settings to the ValueList role, instead, and it will affect the ValueListItems, but not the grid cell.
That was it!!! Thanks a lot Mike. This thing's been bugging me for several days. I'm so glad we finally found the source of the problem. Now I just need to figure out a decent solution to it.
Thanks again for your help.
Richard
rzhu said:Now I just need to figure out a decent solution to it.
I think I gave you a solution, didn't I? You can apply the same setting to the ValueList role instead of the ValueListItem role and that should allow you to color the items on the list without affecting the grid cell.Does that not work?
the problem with that is that ValueList belongs to UltraGridColumn. In our case I'm setting some rows to red based on the bound data, and leave other rows to their default color. So far the only thing I can think of is loop through row.Cells and set the Appearance.ForeColor for each cell to red. Anything more elegant?
rzhu said: the problem with that is that ValueList belongs to UltraGridColumn. In our case I'm setting some rows to red based on the bound data, and leave other rows to their default color. So far the only thing I can think of is loop through row.Cells and set the Appearance.ForeColor for each cell to red. Anything more elegant?
I'm afraid you have completely and utterly lost me here. What does the fact that the ValueList is on the column have to do with anything?
I thought you were using the InitializeRow event to color the cells. That's the best place to do it.
rzhu said:My understanding is that no matter where you set the ValueList foreColor, you are setting it for the whole column, meaning that all the cells in that column will be red. This is different from what we want. We just need certain cells in the column to be red. That's why I said the only way I can think of is to set each cell's Appearance.ForeColor of specific rows to red.
Okay... I don't think you understand what I was suggesting.
If you set an appearance on a ValueListItem (an item, not the whole ValueList), and then you select that item in a cell in the grid, the grid cell will pick up the appearance of that item.
If you set an appearance on the ValueList (the whole list, not a single item), then the appearance will apply to the items on the list, but it will not get picked up by the cell.
So, as I said earlier, what you need to do is open up the isl file and go to the ValueListItem UIRole and reset it so it does not apply any appearances. Then, if you want to apply setting the items on the list, you can apply the same settings that were applied to the ValueListItem role to the ValueList role instead.
Unless I am wrong about all this, of course. Are you saying that you tried this and it doesn't work?
Sorry for jumping around. Here's the full picture:
My understanding is that no matter where you set the ValueList foreColor, you are setting it for the whole column, meaning that all the cells in that column will be red. This is different from what we want. We just need certain cells in the column to be red. That's why I said the only way I can think of is to set each cell's Appearance.ForeColor of specific rows to red.
I hope this clears up the picture, and appreciate all your help.