HI,
My grid show rows' backcolor based on one cell value by using ultraGrid1_InitializeRow.
I wanted those backcolors to be kept when rows selected, instead of default window highlight color.
To implemented that I tried DrawFilter. code is as below. Code runs fine. At run-time it shows row's backcolor (window highlight) is replaced by customised colotr but grid still show default highlight color.
Any idea ? thanks
public class BackColorFilter : IUIElementDrawFilter { public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams) { if (drawParams.Element is RowCellAreaUIElement) { return DrawPhase.BeforeDrawBackColor; } return DrawPhase.None; } public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { switch (drawPhase) { case DrawPhase.BeforeDrawBackColor: RowCellAreaUIElement cell = drawParams.Element as RowCellAreaUIElement; if (cell.Row.Selected && (bool)cell.Row.Cells["Excluded"].Value) { drawParams.AppearanceData.BackColor = cell.Row.Appearance.BackColor; } return true; } return false; } }
Hi,
You only need to change the BackColor on one layer - the layer that is actually drawing the BackColor.
There's a sample DrawFilter to do this here:
DrawFilter for Backcolor - Infragistics Forums
However, there is still an easier way to do it without using a DrawFilter - even if you only want it to affect certain rows.
The thing to do is apply the appearance you want to the cell instead of the row, and in addition to the cell.Appearance, also set the cell.SelectedAppearance.
the reason why i said that is because at run-time the line of code as below shows the backcolor of row has been replaced with customised color (in my case i set as red instead of default highlight text). but grid still show backcolor as highlighttext. beside that UIElementViewer also shows backcolor is still highlight text, not red.
drawParams.AppearanceData.BackColor = cell.Row.Appearance.BackColor;
I do have latest version. But I only want some of selected rows to maintain red color, not all of them. So SelectionOverlayColor seems not useful for me......
after careful looking at UIElementViewer I found there are three layers for each row - row->rowcell->cell. and every layer has backcolor. maybe i need to replace all of them?
Thanks a lot.
I don't understand what you are asking.
liulinglll said:At run-time it shows row's backcolor (window highlight) is replaced by customised colotr but grid still show default highlight color.
You seem to be saying that it both works and does not work. So that does not make sense.
What you are doing here with the DrawFilter is an old workaround that you used to have to do in older versions of the grid, but you probably don't need to do this any more. What version of the grid are you using?
If you have a relatively recent version of the grid, you can just use the SelectionOverlayColor property on the layout.