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.
Maybe what you need to do is, rather than turning off the borders for rows and cells, set the border color to White so it matches the cells and fills in the gaps?