Articles in this section

How to hide the filter bar buttons in the GridDynamicFilter in WinForms GridGroupingControl?

Dynamic filter


The WinForms GridGroupingControl does not have built-in support to hide the filter bar buttons in the GridDynamicFilter. It can be achieved by creating the custom cell renderer and cell model. In the custom cell renderer, we have to override the OnLayout method.


For example, in the below code snippet, create the custom cell model and renderer, then assign the model into the cell type to avoid the filter bar buttons.


Creating a Cell Model

 

C#

public class GridTableFilterCellModelAdv : GridTableFilterBarExtCellModelpublic GridTableFilterCellModelAdv(GridModel grid): base(grid)
  {
    this.SelectAllText = string.Empty;
  }
  
  public override GridCellRendererBase CreateRenderer(GridControlBase control)
  {
    return new GridTableFilterCellRendererAdv(control, this);
  }
}
VB
Public Class GridTableFilterCellModelAdv
  Inherits GridTableFilterBarExtCellModel
  
  Public Sub New(ByVal grid As GridModel)
    MyBase.New(grid)
      Me.SelectAllText = String.Empty
  End Sub
  
  Public Overrides Function CreateRenderer(ByVal control As GridControlBase) As GridCellRendererBase
    Return New GridTableFilterCellRendererAdv(control, Me)
  End Function
End Class
Creating Cell Renderer


C#

public class GridTableFilterCellRendererAdv : GridTableFilterBarExtCellRenderer
{
  public GridTableFilterCellRendererAdv(GridControlBase grid, GridCellModelBase   cellModel): base(grid, cellModel)
  {
 
  }
  
  protected override Rectangle OnLayout(int rowIndex, int colIndex, GridStyleInfo   style, Rectangle innerBounds, Rectangle[] buttonsBounds)
  {
      return new Rectangle(innerBounds.X, innerBounds.Y, innerBounds.Width,    innerBounds.Height);
  }
}
VB
Public Class GridTableFilterCellRendererAdv
 Inherits GridTableFilterBarExtCellRenderer
  
  Public Sub New(ByVal grid As GridControlBase, ByVal cellModel As GridCellModelBase)
   MyBase.New(grid, cellModel)
  End Sub
 
  Protected Overrides Function OnLayout(ByVal rowIndex As Integer, ByVal colIndex As Integer, ByVal style As GridStyleInfo, ByVal innerBounds As Rectangle, ByVal buttonsBounds() As Rectangle) As Rectangle
  Return New Rectangle(innerBounds.X, innerBounds.Y, innerBounds.Width, innerBounds.Height)
  End Function
End Class
Adding CellModel and Assigning CellType


C#

this.gridGroupingControl1.TopLevelGroupOptions.ShowFilterBar = true;
for (int i = 0; i < this.gridGroupingControl1.TableDescriptor.Columns.Count; i++)
{
  this.gridGroupingControl1.TableDescriptor.Columns[i].AllowFilter = true;
}
this.gridGroupingControl1.TopLevelGroupOptions.ShowCaption = false;
GridTableFilterBarExtCellModel filterBarExtCell = new GridTableFilterCellModelAdv(this.gridGroupingControl1.TableModel);
this.gridGroupingControl1.TableModel.CellModels.Add("DynamicFilter", filterBarExtCell);
this.gridGroupingControl1.TableDescriptor.Appearance.FilterBarCell.CellType = "DynamicFilter"; 

VB

Me.gridGroupingControl1.TopLevelGroupOptions.ShowFilterBar = True
For i As Integer = 0 To Me.gridGroupingControl1.TableDescriptor.Columns.Count - 1
  Me.gridGroupingControl1.TableDescriptor.Columns(i).AllowFilter = True
Next i
Me.gridGroupingControl1.TopLevelGroupOptions.ShowCaption = False
Dim filterBarExtCell As GridTableFilterBarExtCellModel = New GridTableFilterCellModelAdv(Me.gridGroupingControl1.TableModel)
Me.gridGroupingControl1.TableModel.CellModels.Add("DynamicFilter", filterBarExtCell)
Me.gridGroupingControl1.TableDescriptor.Appearance.FilterBarCell.CellType = "DynamicFilter" 

The screenshot below illustrates the Hiding of filterbar buttons in GridGroupingControl.

Hide the filter bar buttons

Samples:

C#: FilterBar_CS

VB: FilterBar_VB

 

Reference Link: Dynamic filter 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied