Hi
I have a Ultragrid with two bands. the second band should inherit the backcolor from its parentrow.is this somehow possible?
Currently I'm doing it like:
//InitializeRow eventif(e.Row.Band.Key == "FK_DispositionProducts_Disposition") { if(e.Row.ParentRow.Index % 2 == 0) e.Row.Appearance.BackColor = e.Row.ParentRow.Band.Override.RowAppearance.BackColor; else e.Row.Appearance.BackColor = e.Row.ParentRow.Band.Override.RowAlternateAppearance.BackColor; }
this code was just for testing, I know it will affect performance :-)
is there a better way to what I want?
Mike,
Thanks for the response, very helpful and informative. For now, I am using the ResolveAppearance method. It is working correctly. If it should become an issue I will re-evaluate at that time. Thanks for your time!
Sincerely,
Duncan
Hi Duncan,
The BackColor of a row goes through a very long and complex resolution process. The row.Appearance.BackColor will not return the actual on-screen color of the row, it will only return the color you set, if any. The same goes for any other appearance property that affects the rows.
So you cannot do what you are trying to do here by checking a single property on the grid.
If you do not use AppStylist and you apply an appearance to:
e.Layout.Override.RowAlternateAppearance.BackColor
Then you could assume that the Color you applied to this property is applied to every alternate row. Thus, you could check the IsAlternate property on the row and assume that the row is using the color you set (e.Layout.Override.RowAlternateAppearance.BackColor).
But this is not necessarily true, since there are many other appearance properties that could override this setting, such as row.Appearance.
You can get the actual on-screen resolved appearance of the row by using the row.ResolveAppearance method. But this probably isn't what you want, either, because if the row is selected, this will return the selected colors and not the normal row colors.
So, to achieve what you want here, you will have to figure out what kind of assumptions you can make about your application. Maybe you are not allowing selection. Or maybe you know that you are not setting row.Appearance anywhere in your application.
Hey Mike,
Thanks for the reply. Let me try and break it down, as this is part of a huge project. I will see if I can reproduce in a much smaller one after I finish explaining here.
I'm using the AppStylist to specify settings for the parent band's alternating row color. These settings in AppStylist apply to a GridRow's AlternateItem.
I also have the code above running in an intializerow event. While tracing this event I noticed that the e.Row.ParentRow.Band.Override.RowAlternateAppearance.BackColor property was always returning white, regardless of IsAlternate.
I tried moving away from AppStylist and using the initializeLayout routine to set the alternating color via
e.Layout.Override.RowAlternateAppearance.BackColor, however it had the same results, the Parent reference backcolor was always white.
After tracing, I re-examined the e.Row.ParentRow.Band.Override.RowAlternateAppearance.BackColor and noticed the Band property in there.
so I changed e.Layout.Override.RowAlternateAppearance.BackColor to be
e.Layout.Bands(0).Override.RowAlternateAppearance.BackColor and that worked. It allowed me to be able to color the child band the same as the parent.
So this is my question. Is what I'm describing desired behavior? My guess would be no, because it appears to prevent me from using the AppStylist.
Thanks for your time on this Mike. I'll work on a small sample to see if I can recreate.
I'm sorry, but I'm not able to follow what you are trying to do here or what the problem is.
Perhaps you could post a small sample project demonstrating the issue you are experiencing?
The code here is attempting to apply an appearance to each child row based on whether the parent row is an alternate row or not. Is that what you are trying to do?
It sounds like maybe you are trying to have the child rows alternate their colors, as well. But like I said, I'm having a really hard time following you here.
I have a small issue with performing the above operation. I'm trying to setup a Style for the BackColor on the GridRow object for AlternateItem. If I set this value, then use the almost identical code from above, the child band in the alternate row does not have the color applied. The same problem exists if you don't use a Style but set the RowAlternateAppearance.BackColor on the entire layout in the grid's initlayout method. Based on the e.Row.ParentRow.Band property, I changed my code to set the parent band's RowAlternateAppearance.BackColor and then it worked. Note that when using either the Style or the root Layout settings the parent band does have the color applied. It's just that during the initrow, referencing it by band does not have the applied color. I hope I explained this clearly enough. It almost seems as though this might be a bug, but I hesitate to call it as such. Any help you might be able to give is greatly appreciated.
Thanks,