Unable to hide cells border of particular column in the UltraGrid

610 Views Asked by At

I have added drawfilter to hide the cells of a particular column in ultragrid by setting the border style to none and removed the borders of the cell. But the border is still visible. Don't know what I am missing.

class MyDrawFilter : IUIElementDrawFilter
{
    DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams)
    {
        if (drawParams.Element is CellUIElement)
        {
            UltraGridCell myCell = drawParams.Element.GetContext(typeof(UltraGridCell)) as UltraGridCell;

            if (myCell.Column.Key == "col1")
            {
                return Infragistics.Win.DrawPhase.BeforeDrawBorders;
            }
            return DrawPhase.None;
        }
        return DrawPhase.None;
    }

    bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
    {
        Border3DSide border = drawParams.Element.BorderSides;
        border &= ~Border3DSide.Middle;
        border &= ~Border3DSide.Right;
        drawParams.DrawBorders(UIElementBorderStyle.None, border);
        return true;

    } 
}
2

There are 2 best solutions below

0
Jackdaw On BEST ANSWER

The custom DrawFilter below draw border for all cells in a UltraGrid except defined column:

public class NoRowBorderDrawFilter : IUIElementDrawFilter
{
    public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
    {
        switch (drawPhase)
        {
            case DrawPhase.BeforeDrawBorders:                   
                break;

            case DrawPhase.AfterDrawElement:
                if (drawParams.Element is RowCellAreaUIElement aCellUIElement)
                {
                    var cElements = aCellUIElement.ChildElements;
                    for (int i = 0; i < cElements.Count; i++)
                    {
                        if (cElements[i] is CellUIElement cui && cui.Column.Key != "HardDrive")
                        {
                            drawParams.DrawBorders(UIElementBorderStyle.Dotted, Border3DSide.Bottom, Rectangle.Inflate(cui.Rect, 0, 0));
                        }
                    }
                }
                break;
        }
        return true;
    }

    public Infragistics.Win.DrawPhase GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams)
    {           
        return (drawParams.Element is RowCellAreaUIElement) 
            ? DrawPhase.AfterDrawElement | DrawPhase.BeforeDrawBorders 
            : DrawPhase.None;        
    }
}

The trick here is using DrawPhase.AfterDrawElement for drawing the row borders.

When filter defined above applied the UltraGrid from some Infragistics example the control look like on the screen-shot below (filtered column marked in red):

enter image description here

2
wnvko On

Each cell draws its left and right border. Your code correctly removes the borders of the cell in col1, but it does not remove the borders of its neighbor cells. So if you have table like this:

|col1 |col2 |col3 |col4 |

|cell1|cell2|cell3|cell3|

and you need to remove the left and right borders of cell2 you need to:

  • remove the right border of cell1.
  • remove the left and right border of cell2.
  • remove the left border of cell 3.

Note top and bottom borders are coming from RowCellAreaUIElement. If you need to remove and these borders you should manipulate and these elements.

Here is how the element tree of the grid may look like

UltraGridUIElement - this is the entire grid
    DataAreaUIElement - this is where the data is shown
        RowColRegionIntersectionUIElement - this is where scrollbars will appear
            RowUIElement - this is where row is drawn
                RowSelectorUIElement - row selectors if any
                RowCellAreaUIElement - cells container - this element draws most left, most right and top and bottom borders of the row
                    CellUIElement - cell - this draw left and right cell borders
                    CellUIElement
                    CellUIElement
                    CellUIElement
                RowCellAreaUIElement
                    CellUIElement
                    CellUIElement
                    CellUIElement
                    CellUIElement

So you have CellUIElement responsible for drawing left and right cell borders. Then you have RowCellAreaUIElement responsible for drawing top and bottom cell borders at once, as well as drawing the left border of first cell and right border of the last cell.