We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to hide the custom option in the filterbar dropdown in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl

Hide the custom option

To achieve this, implement a custom filter bar cell that derives the cell model or cell renderer from the GridTableFilterBarCellModel or GridTableFilterBarCellRenderer.

The GridTableFilterBarCellModel.FillWithChoices method is overridden to remove the string Custom from the list.


//Overrides FillWithChoices to remove the Custom option from the list.
public override void FillWithChoices(ListBox listBox, GridStyleInfo style, out bool exclusive)
    exclusive = true;
    GridTableCellStyleInfo tableStyleInfo = (GridTableCellStyleInfo)style; 
    object[] items = (object[])GetFilterBarChoices(tableStyleInfo.TableCellIdentity);
    if(items != null)
       foreach (object item in items)
          if(item is DBNull)
          else if (item != null)


'Overrides FillWithChoices to remove the Custom option from the list.
Public Overrides Sub FillWithChoices(ByVal listBox As ListBox, ByVal style As GridStyleInfo, <System.Runtime.InteropServices.Out()> ByRef exclusive As Boolean)
    exclusive = True
    Dim tableStyleInfo As GridTableCellStyleInfo = CType(style, GridTableCellStyleInfo)
    Dim items() As Object = CType(GetFilterBarChoices(tableStyleInfo.TableCellIdentity), Object())
    If items IsNot Nothing Then
       For Each item As Object In items
           If TypeOf item Is DBNull Then
           ElseIf item IsNot Nothing Then 
           End If
       Next item
    End If
End Sub

The GridTableFilterBarCellModel.Select method is rewritten with the Select_withoutcustom method that specifies the index for the selected item. You can pass the index for the Custom selected item as 0.


//Customizes the Select method to hide the Custom option.
public void Select_WithoutCustom(GridTableCellStyleInfoIdentity tableCellIdentity, int index)
    if(index >= 0)
       if(index == 0)
       else if (index == 1)
          SelectItem(tableCellIdentity, 0);
         SelectItem(tableCellIdentity, index - 1);


'Customizes the Select method to hide the Custom option.
Public Sub Select_WithoutCustom(ByVal tableCellIdentity As GridTableCellStyleInfoIdentity, ByVal index As Integer)
    If index >= 0 Then
       If index = 0 Then
       ElseIf index = 1 Then
          SelectItem(tableCellIdentity, 0)
          SelectItem(tableCellIdentity, index - 1)
       End If
    End If
End Sub

The GridTableFilterBarCellModel.ListBoxMouseUp() method is overridden to invoke the Select_withoutcustom method instead of the Select method.


//Overrides the ListBoxMouseUP method to call the Customized Select method instead of the usual 'Select' method.
protected override void ListBoxMouseUp(object sender, MouseEventArgs e)
    GridTableCellStyleInfo tableStyleInfo = (GridTableCellStyleInfo)this.StyleInfo;
    GridTableCellStyleInfoIdentity tableCellIdentity = tableStyleInfo.TableCellIdentity;
    Model.Select_WithoutCustom(tableCellIdentity, this.ListBoxPart.SelectedIndex);
    SetTextBoxText(GetFilterBarText(StyleInfo), false);// don't call base class - ignore.
    String _FilterBarValue = this.ListBoxPart.SelectedItem.ToString();
    GridTableControl _grid = Grid as GridTableControl;
    int _filed = _grid.TableDescriptor.ColIndexToField(ColIndex);
    string _columnName = _grid.TableDescriptor.VisibleColumns[_filed].Name;
    if(_FilterBarValue != "(All)" && _FilterBarValue != "Empty")
       _grid.TableDescriptor.RecordFilters.Add(_columnName, FilterCompareOperator.Equals, this.ListBoxPart.SelectedItem);


'Overrides the ListBoxMouseUP method to call the Customized Select method instead of the usual Select method.
Protected Overrides Sub ListBoxMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
  Dim tableStyleInfo As GridTableCellStyleInfo = CType(Me.StyleInfo, GridTableCellStyleInfo)
  Dim tableCellIdentity As GridTableCellStyleInfoIdentity = tableStyleInfo.TableCellIdentity
  Model.Select_WithoutCustom(tableCellIdentity, Me.ListBoxPart.SelectedIndex)
  SetTextBoxText(GetFilterBarText(StyleInfo), False) ' don't call base class - ignore.
  Dim _FilterBarValue As String = Me.ListBoxPart.SelectedItem.ToString()
  Dim _grid As GridTableControl = TryCast(Grid, GridTableControl)
  Dim _filed As Integer = _grid.TableDescriptor.ColIndexToField(ColIndex)
  Dim _columnName As String = _grid.TableDescriptor.VisibleColumns(_filed).Name
  If _FilterBarValue <> "(All)" AndAlso _FilterBarValue <> "Empty" Then
     _grid.TableDescriptor.RecordFilters.Add(_columnName, FilterCompareOperator.Equals, Me.ListBoxPart.SelectedItem)
  End If
End Sub

A new CellType is created by adding the instance of the derived GridTableFilterBarCellModel class into the GridGroupingControl’s cellmodels.


//Adds the GridTableFilterBarCell into the cell model
this.gridGroupingControl1.TableModel.CellModels.Add("GridTableFilterBarCell", new MYGridTableFilterBarCellModel(this.gridGroupingControl1.TableModel));
//Assigns the FilterBarCelltype as GridTableFilterBarCell
this.gridGroupingControl1.TableDescriptor.Appearance.FilterBarCell.CellType = "GridTableFilterBarCell";


'Adds the GridTableFilterBarCell into the cell model
Me.gridGroupingControl1.TableModel.CellModels.Add("GridTableFilterBarCell", New MYGridTableFilterBarCellModel(Me.gridGroupingControl1.TableModel))
'Assigns the FilterBarCelltype as GridTableFilterBarCell
Me.gridGroupingControl1.TableDescriptor.Appearance.FilterBarCell.CellType = "GridTableFilterBarCell"

After applying the properties, the Grid is displayed as follows.

Hide the custom option in filter bar

Figure 1: Hiding the custom option


C#: Hiding custom_option

VB: Hiding custom_option

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment
maurizio ziraldo
Jun 11, 2015
This solution has a problem when you have some hidden columns. Add this line of code to your sample in Form1.cs: this.gridGroupingControl1.TableDescriptor.VisibleColumns.Remove("Name"); then run the sample and try to filter by WorkingBranch: you will see that the filter is applied to the wrong column City. To avoid this you can change this line: string _columnName = _grid.TableDescriptor.Columns[_filed].Name; with string _columnName = _grid.TableDescriptor.VisibleColumns[_filed].Name; in ListBoxMouseUp event of custom Cell Model. Reply
Venkatesh Sundaram [Syncfusion]
Jun 12, 2015
Hi Maurizio , Thanks for your valuable suggestions. We have modified the sample as per your suggestions and the sample link is updated in the kb article. please let us know if you have any concerns. Thanks and Regards, Venkat. Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile