Category / Section
How to handle the dates as strings in the WinForms PivotGridControl?
1 min read
Handle the dates as strings
When the date is set as a string format, it sorts the records based on the string and does not sort the record correctly in the Date string. So, use the dataset and apply the format property in the PivotItem class.
C#
//Sets date time column. dt.Columns.Add("Date", GetType(DateTime)) //Sets Date Time format to the Pivot Row. this.pivotGridControl1.PivotRows.Add(New PivotItem With {.FieldMappingName = "Date", .Format="MM/dd/yyyy", .TotalHeader = "Total"})
VB
‘Sets date time column dt.Columns.Add("Date", GetType(DateTime)) ‘Sets Date Time format to the Pivot Row. Me.pivotGridControl1.PivotRows.Add(New PivotItem With {.FieldMappingName = "Date", .Format="MM/dd/yyyy", .TotalHeader = "Total"})
The following screenshots display the date strings before formatting and after formatting:
Figure 1: Before formatting
Figure 2: After formatting
Samples: