Hi,
Within a WinForms UlraGrid, I am looking for a means (via code) to alter the appearance of an entire row, whenever a targeted column value meets a certain condition. For example, I already know that I can target the respect cell via the ConditionValueAppearance. The closest I could find to what might work is the ConditionAppearanceRow Class. Unfortunately you don't provide any code snippets to demonstrate how this class is hooked up with a given DisplayLayout Band.
In any case, I need this capability through code, so I can set the row appearance on the fly. If there is another way to do this, I am all ears.
Thanks,
Lacy
Hi Lacy,
Conditional Appearances are really useful for setting things up at Design-time. But at run-time, they actually require more code than neccessary and it's much easier to do things a different way.
I recommend using the InitializeRow event of the grid. This event is specifically designed to help you with situations just like this one where you want to color the row based on a value inside that row. All you do is handle the event, examine the row and it's cells and then set the Appearance properties on the row to suit your needs.
Hi Mike,
I implemented a conditional appearance in my initialize row event (changes backcolor based on value), but now I am seeing a slower response time when I change the rowfilter on the dataview the ultragrid is bound to. Do you have any performance tips?
Thanks,Kelly
Thanks Mike,
I ended up doing it with InitializeRow indeed.
It's not as cool, but it works fine.
InitializeRow event worked as expected (as I wanted to update the content of the cells), but the row header of each row shows that the row is in edit mode (i.e. the pencil sing with ...).
How to get rid of this.
Thanks in advance,
Ganesh.
Hello Ganesh,
I am not sure about what pencil you are talking about. Are you saying that in the InitializeRow event if you are changing the values in the cells you are getting some sort of images in the RowSelectors? Could you please provide a small sample project or a screenshot.
Hi Boris,
Here is the snap.
Complications: - Grid has couple of bands that's it.
image not shown in the editor so attached it.
Hi Gregory,
Sorry, I got a little mixed up there. I thought we added a SelectedAppearance to the row, but it's actually only available on the cell.
Anyway, I think you can achieve essentially the same thing using the row.CellAppearance, instead of row.Appearance. CellAppearance will override the selected appearance, I think.
If I am wrong, then the alternative would be to loop through cells in the row and apply the appearance to the cell.Appearance and possibly also the cell.SelectedAppearance and maybe also the cell.ActiveAppearance if you want.
Yes. In addition to setting the Appearance on the row, you can set the SelectedAppearance, also. This was added a couple of years back, so if you are using a very old version of the controls, it might not be available. In that case, it's much more difficult to handle and you would have to use a DrawFilter.
Hey Mike,
I have my grid row backcolor turning red thanks to your posts, but if my red row happens to be the first row in the grid when that row is the selected row the selected row color of orange seems to take precidence over the red color. As soon as I click off of that row then I can see the red backcolor. Is there a way to force the red backcolor to override the selected row color?
Gregory
Normal 0 false false false EN-US ZH-CN X-NONE
e.Row.Update(); has done the trick
Many Thanks Boris.