Dear all,
I'm almost completely unfamiliar with Infragistics' Winforms app styling, and require some (ideally expeditious!) assistance. The appearance of active & selected rows in my grid seems to be determined by resources in an ISL file named GridRow_'Selected|Active'. It seems that these resources get associated with the appropriate properties by naming convention alone, as they appear to be defined, but not at any point used or assigned - is this correct? What I want to do is simple: override the ISL-defined active/selected row style for a particular cell in each currently active or selected row. At present, I'm trying to achieve this through setting the cell's SelectedAppearance (UltraGridCell has neither Override nor ActiveRowStyle properties) during InitializeLayout. This, however, is doing nothing for me, despite the fact that I've changed the ResolutionOrder for UltraGrid to ApplicationThenControl in the ISL. The cell continues to inherit its appearance from the "GridRow_'Selected|Active'" style of its parent row.
Please can someone tell me how I can change the active & selected appearances of this cell?
Many Thanks Indeed,
James
Hi Danny,
You might want to take a look at the two original samples I posted for Foreground and Background colors. The foreground of the cell is drawn by a different UIElement than the background.
Your code is not even really looking at the elements in question, you are just assuming that you should change the appearance for any element that has a cell context and you are changing the appearance of both the background and the foreground for any such element. This approach is too broad and it's no wonder it's erasing the text.
You need to use a more targetted approach to make sure that you only change the ForeColor of the AppearanceData when you are handling BeforeDrawForeGround of the element that draws the ForeGround (which I beleive is a TextUIElement). And you need to make sure that you only change the Background color in the BeforeDrawBackground of the element that draws the BackColor, which I beleive is the CellUIElement.
Please ignore my last post on this thread - pure idleness on my part. Problem now resolved.
Thanks for all your help.
Best regards,
Hi Mike,
That's perfect - thanks again for your help. There's just one final problem that I'm struggling to overcome: the code underneath is, exactly as desired, setting the cell's BG colour as defined in its Appearance property (which I assign during InitializeLayout), but it's also erasing its text. If I uncomment the commented statements & comment out the uncommented statements in the same block, I get no effect at all: the Active/selected row style prevails.
Could you please briefly let me know where I'm going wrong, and strike the final blow for this problem!?
Best Regards,
P.S. the filter's misnamed since clearly I want to retain the forecolour too; but this is the least of my worries right now :)
public class RetainCellBackgroundDrawFilter : IUIElementDrawFilter {
public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams) { if ((drawParams.Element is EmbeddableUIElementBase) && (drawParams.Element.GetContext(typeof(UltraGridCell)) != null)) { return DrawPhase.BeforeDrawBackColor | DrawPhase.BeforeDrawForeground; } return new Infragistics.Win.DrawPhase(); } public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams) { UltraGridCell aCell;
switch (drawPhase) { case DrawPhase.BeforeDrawBackColor: aCell = drawParams.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (aCell != null && (aCell.Selected || aCell.Row.Selected || aCell.Column.Header.Selected)) { if (aCell.HasAppearance && (aCell.Appearance == LegalStatusConfig.CellBgColourSafe || aCell.Appearance == LegalStatusConfig.CellBgColourUnsafe)) { //drawParams.AppearanceData.BackColor = aCell.Appearance.BackColor; //drawParams.AppearanceData.BackColor2 = aCell.Appearance.BackColor2; //drawParams.AppearanceData.BackGradientStyle = aCell.Appearance.BackGradientStyle; drawParams.AppearanceData = aCell.Appearance.Data; } } break; case DrawPhase.BeforeDrawForeground: aCell = drawParams.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (aCell != null && (aCell.Selected || aCell.Row.Selected || aCell.Column.Header.Selected)) { if (aCell.HasAppearance && (aCell.Appearance == LegalStatusConfig.CellBgColourSafe || aCell.Appearance == LegalStatusConfig.CellBgColourUnsafe)) { //drawParams.AppearanceData.FontData.Bold = aCell.Appearance.FontData.Bold; //drawParams.AppearanceData.ForeColor = Color.Black; drawParams.AppearanceData = aCell.Appearance.Data; } } break; } return false; }
}
Hi James,
Sorry, I misunderstood the question.
For a single cell, that question is answered here: DrawFilter for Backcolor - Infragistics Forums
Or... you might just want to wait until the v9.2 release. We will be adding some new functionality to make this easier. :)
Hello Mike,
Many thanks for taking the time to reply. Unless I've misunderstood, the thread you kindly reference doesn't quite address my query. I wish to retain the active row highlighting defined in the ISL, but override it at runtime for a particular cell in the currently active or selected row. If that isn't possible, that's fine. If it is, and you could point me rougly in the direction of how it can be done, that would be even better!