)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the date format in filter bar of DynamicFilter in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: May 18, 2016 |
Last Revised Date: February 12, 2020

Customize the date format in filter bar of dynamic filter

In order to customize the date format in filterbar cell, Format property of FilterBarCell property, FilterBarSelectedItemChanged and TableControlDrawCellDisplayText events can be used.

C#

//Customize the DateFormat.
this.gridGroupingControl1.TableDescriptor.Columns["Date"].Appearance.FilterBarCell.Format = "dd-MMM-yyyy";
this.gridGroupingControl1.TopLevelGroupOptions.ShowFilterBar = true;
for (int i = 0; i < this.gridGroupingControl1.TableDescriptor.Columns.Count; i++)
{
   this.gridGroupingControl1.TableDescriptor.Columns[i].AllowFilter = true;
}
GridDynamicFilter dynamicFilter = new GridDynamicFilter();
dynamicFilter.WireGrid(this.gridGroupingControl1);
 
//Triggering the FilterBarSelectedItemChanged event. 
this.gridGroupingControl1.FilterBarSelectedItemChanged += gridGroupingControl1_FilterBarSelectedItemChanged;
//Triggering the TableControlDrawCellDisplayText event.
this.gridGroupingControl1.TableControlDrawCellDisplayText += gridGroupingControl1_TableControlDrawCellDisplayText;
 
//Handling the TableControlDrawCellDisplayText event.
void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
   GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.Inner.Style;
   if (style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "Date" && style.TableCellIdentity.TableCellType == GridTableCellType.FilterBarCell)
   {
      if (style.Text != "(All)" && style.Text != "(Custom....)" && style.Text != "(Empty)")
         e.Inner.DisplayText = string.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(style.Text));
   }
}
 
//Handling the FilterBarSelectedItemChanged event.
void gridGroupingControl1_FilterBarSelectedItemChanged(object sender, FilterBarSelectedItemChangedEventArgs e)
{
   if (e.Column != null && e.Column.Name == "Date")
   {
      int row = this.gridGroupingControl1.TableControl.CurrentCell.RowIndex;
      int col = this.gridGroupingControl1.TableControl.CurrentCell.ColIndex;
      GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(row, col);
      GridTableFilterBarExtCellRenderer renderer = this.gridGroupingControl1.TableControl.GetCellRenderer(row, col) as GridTableFilterBarExtCellRenderer;
      renderer.ControlText = string.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(style.Text));
   }
}

VB

'Customize the DateFormat.      
Me.gridGroupingControl1.TableDescriptor.Columns("Date").Appearance.FilterBarCell.Format = "dd-MMM-yyyy"
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
Dim dynamicFilter As New GridDynamicFilter()
dynamicFilter.WireGrid(Me.gridGroupingControl1)
 
'Triggering the FilterBarSelectedItemChanged event. 
AddHandler Me.gridGroupingControl1.FilterBarSelectedItemChanged, AddressOf gridGroupingControl1_FilterBarSelectedItemChanged
'Triggering the TableControlDrawCellDisplayText event.
AddHandler Me.gridGroupingControl1.TableControlDrawCellDisplayText, AddressOf gridGroupingControl1_TableControlDrawCellDisplayText
 
'Handling the TableControlDrawCellDisplayText event.
void gridGroupingControl1_TableControlDrawCellDisplayText(Object sender, GridTableControlDrawCellDisplayTextEventArgs e)
   Dim style As GridTableCellStyleInfo = CType(e.Inner.Style, GridTableCellStyleInfo)
   If style.TableCellIdentity.Column IsNot Nothing AndAlso style.TableCellIdentity.Column.Name = "Date" AndAlso style.TableCellIdentity.TableCellType = GridTableCellType.FilterBarCell Then
      If style.Text <> "(All)" AndAlso style.Text <> "(Custom....)" AndAlso style.Text <> "(Empty)" Then
         e.Inner.DisplayText = String.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(style.Text))
      End If
   End If
 
'Handling the FilterBarSelectedItemChanged event.
void gridGroupingControl1_FilterBarSelectedItemChanged(Object sender, FilterBarSelectedItemChangedEventArgs e)
   If e.Column IsNot Nothing AndAlso e.Column.Name = "Date" Then
      Dim row As Integer = Me.gridGroupingControl1.TableControl.CurrentCell.RowIndex
      Dim col As Integer = Me.gridGroupingControl1.TableControl.CurrentCell.ColIndex
      Dim style As GridTableCellStyleInfo = Me.gridGroupingControl1.TableControl.GetTableViewStyleInfo(row, col)
      Dim renderer As GridTableFilterBarExtCellRenderer = TryCast(Me.gridGroupingControl1.TableControl.GetCellRenderer(row, col), GridTableFilterBarExtCellRenderer)
      renderer.ControlText = String.Format("{0:dd-MMM-yyyy}", Convert.ToDateTime(style.Text))
   End If

 

Show the formatting data style in filter bar

Samples:

C#: CustomizeDateFormat_CS

VB: CustomizeDateFormat_VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/filtering

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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
Live Chat Icon