We have up to 50 rows in a wingrid shown as a compressed cardview. I have been asked by a user if it would be possble to change the caption colour of each row depending on a status. This way they could see at a glance the status of an item, even when collapsed.
Is this possible ?
TIA
Hi,
There's no property to set the appearance of a card caption on an individual row. But this could be done using a DrawFilter.
DrawFilters can be a bit intimidating if you haven't used them before, but this one is actually a pretty simple one.
private void Form1_Load(object sender, System.EventArgs e) { this.ultraGrid1.DrawFilter = new CardCaptionDrawFilter(); }
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) {
// We must turn off themes on the card captions in order to be able to change their // colors. Otherwise, the themed colors will override the drawing. // ov.CardCaptionAppearance.ThemedElementAlpha = Alpha.Transparent; }
public class CardCaptionDrawFilter : IUIElementDrawFilter { #region IUIElementDrawFilter Members bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { UltraGridRow row = drawParams.Element.GetContext(typeof(UltraGridRow)) as UltraGridRow; if (row != null) { if ((int)row.Cells["Int32 1"].Value > 5) drawParams.AppearanceData.BackColor = Color.Red; else drawParams.AppearanceData.BackColor = Color.Blue; } return false; } DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { if (drawParams.Element is CardCaptionUIElement) return DrawPhase.BeforeDrawBackColor; return DrawPhase.None; } #endregion }
Hmm, it doesn't seem to be working.
In the CardCaptionDrawFilter class, I set
drawParams.AppearanceData.BackColor = System.Drawing.Color:FromName("Indian Red").
I know that it is executing this line of code, because I displayed the colour before and after this line, and that data was shown on the form. However, the before message of
drawParams.AppearanceData.BackColor:ToString()
gives Color [InactiveCaption]
and the after message
as well.
(i.e the setting of the backcolor does not change it)
Are you sure you turned off themes as I did in my example?
If that doesn't help, then I'm not sure why it's not working. This code worked fine for me using the latest service release of NetAdvtange for WinForms 2008 Volume 2.
I have
ultragrid1.DisplayLayout.Override.CardCaptionAppearance.ThemedElementAlpha = Alpha.Transparent
in the ultraGrid1_InitializeLayout event
i didn't know what the ov was in your example
Oops, sorry about that. You're right, though, that's exactly what it was.
I don't know what's happening there. Can you post a small sample project demonstrating the behavior you are getting?
Awww, crap. It works in c# ... I'm using Progress 10.2A and there must be an issue somewhere. Let me try a simple project in Progress to mimic the c# one.
I will try to hack one out. What I don't understand is why the color doesn't change after I assign a new value. Are there any other settings on the grid that may affect this mechanism ?