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)
Thanks for this. I have a followup question though ;)
How would I programmatically force a redraw of the caption if the value of the cell changes from 4 to 6 ? Would a refresh do the job ?