Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2005
Appearance of Filter row cell
posted

Hi,

Is there a way to change the Appearance of filter cells in edit mode? What I would like to do is to change foreground color and background color of a filter cell when it is in edit mode.

Any suggestion and help is greatly appreciated!

Best regards,
Shaolin

  • 21795
    Verified Answer
    Offline posted

    Hello Shaolin,

    If you need to set the appearance of all the cells in grid’s filter row, you may set FilterCellAppearance or FilterRowAppearance of the Override like this:

    var layout = this.ultraGrid1.DisplayLayout;
    var ov = layout.Override;
     
    ov.FilterCellAppearance.BackColor = Color.Blue;
    ov.FilterRowAppearance.BackColor = Color.Green;

    If what you need is to set the appearance of a single cell in filter row you will need to use some workaround, as grid does not expose method or property allowing you to achieve this. One possible solution is to handle BeforeEnterEditMode and AfterExitEditMode evnets of the grid. In before event check if the edited cell is filter row cell. If so, set the necessary appearance. In after event check again the cell if it is filter row cell – if so reset its appearance. You can use code like this:

    private void UltraGrid1_BeforeEnterEditMode(object sender, CancelEventArgs e)
    {
        //  Get a reference to the grid
        var grid = sender as UltraGrid;
        if(grid == null)
            return;
     
        //  Get a reference to the active cell
        var activeCell = grid.ActiveCell;
        if(activeCell == null)
            return;
     
        //  If active cell is filter row cell set its appearance
        if(activeCell.IsFilterRowCell == true)
        {
            //  As each time user clicks on filter row cell you will set cell's appearance
            //  it is better to cache the appearance in a private field. This way you will
            //  decrease the memory footprint
            if(this.editApp == null)
            {
                //  Initialize edit appearance if not yet done
                this.editApp = new Infragistics.Win.Appearance();
                this.editApp.BackColor = Color.Red;
            }
     
            if(this.defaultApp == null)
            {
                //  Save current cell appearance
                this.defaultApp = new Infragistics.Win.Appearance();
                this.defaultApp = (Infragistics.Win.Appearance)activeCell.Appearance.Clone();
            }
     
            //  Set cell appearance
            activeCell.Appearance = this.editApp;
        }
    }
     
    private void UltraGrid1_AfterExitEditMode(object sender, EventArgs e)
    {
        //  Get a reference to the grid
        var grid = sender as UltraGrid;
        if(grid == null)
            return;
     
        //  Get a reference to the active cell
        var activeCell = grid.ActiveCell;
        if(activeCell == null)
            return;
     
        //  If the cell is filter row cell restore its default appearance
        if(activeCell.IsFilterRowCell == true && this.defaultApp != null)
            activeCell.Appearance = this.defaultApp;
    }

    Attached is a small sample where I have implemented this approach. Please check my sample and let me know if this is what you are looking for or if I am missing something.

    UltraGridFilterCellAppearance.zip