The article "Draw Filters" in Help shows how to draw a border around a specified edge of a grid cell.
For each cell, I would like to draw a left border, and/or a right border, or no border, depending on which column the cell is in. I could do it if, in the DrawElement method of my draw filter class, I could get a reference to the UltraGridCell that is currently being drawn. I can get a reference to the grid as drawParams.Element.Control, but I can't see how to get a reference to the UltraGridCell.
Any ideas?
I think you can get the cell in the DrawElement method like this:
if (drawParams.Element is CellUIElement)
That didn't work -- myCell is always null.
This is the code I used:
class MyDrawFilter : IUIElementDrawFilter{ DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { if (drawParams.Element is RowCellAreaUIElement) return Infragistics.Win.DrawPhase.BeforeDrawBorders; return DrawPhase.None; } bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { UltraGridCell myCell = drawParams.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (myCell != null) throw new ApplicationException("Found non-null cell!"); return false; }}
The problem is that your two methods are inconsistent. You are checking for RowCellAreaUIElement in GetPhasesToFilter. So the element in DrawElement will never be a cell. You need to check for CellUIElement.
I actually used this to solve a somewhat similar problem with an UltraGridDocumentExporter, so my solution might not apply to you.
I included the following in the BeginExport event handler of an UltraGridDocumentExporter, which might be analogous to the InitializeLayout event of an UltraGrid:
e.Layout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.None; e.Layout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.None; e.Layout.Override.RowAppearance.BorderColor = System.Drawing.Color.Transparent; e.Layout.Override.CellAppearance.BorderColor = System.Drawing.Color.Transparent;
I can't say I exactly understand why this worked.
I have had good results with setting BorderColor = System.Drawing.Color.Transparent.