I have a grid that contains an integer column that represents time in seconds. Currently I simply have a computed column that converts seconds to time string and I hide the original. However, this obviously does not allow me to use the summaries as its a string.I need to do 2 things as follows...1) Although I'm happy with the default summaries (Sum, avg, max and min) I need to format the results to convert the time in seconds to something like '1 hr 20 mins 12 secs'. I have a function that can do this yet I'm not sure how I can override the [summary].DisplayFormat to allow me to utilise this custom function. It would need to use the summary value and pass it down to my function which would return a correctly formatted string.2) I would also like to know how I can get the [column].format function to utilise my own custom function to generate the string value that will be displayed in the grid.I assume that there is some way to do this, as there is a way to override the summaries via an interface.Thanks!
Hai,
Sample code to sum the time value :
Public Class TimeSummaryCalculator Implements ICustomSummaryCalculator Private lnSeconds As Decimal = 0#Region "ICustomSummaryCalculator Procedures & Functions" Private Sub ICustomSummaryCalculator_AggregateCustomSummary(ByVal summarySettings As SummarySettings, ByVal row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary Dim loValue As Object = row.Cells(summarySettings.SourceColumn).Value lnSeconds += QbConvert(loValue, "T", "S") 'qbconvert is a function which is use to convert seconds to time and viceversa End Sub Private Sub ICustomSummaryCalculator_BeginCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.BeginCustomSummary lnSeconds = 0 End Sub Private Function ICustomSummaryCalculator_EndCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) As Object Implements ICustomSummaryCalculator.EndCustomSummary Return QbConvert(lnSeconds, "S", "T") 'qbconvert is a function which is use to convert seconds to time and viceversa End Function#End RegionEnd Class
Add the below line in your code
Dim QbGrdSummary As New SummarySettingsQbGrdSummary = Grid.DisplayLayout.Bands(0).Summaries.Add(Grid.DisplayLayout.Bands(0).Columns("timecolumn").Key, SummaryType.Custom, _ New TimeSummaryCalculator, Grid.DisplayLayout.Bands(0).Columns("timecolumn"), SummaryPosition.UseSummaryPositionColumn, _ Grid.DisplayLayout.Bands(0).Columns("timecolumn")):
Hi, how's it going?
There sure is a way to do this! Check out this help topic that explains how to create your own custom summary calculator, how to implement the logic, as well as how to assign it to the WinGrid control:
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=Infragistics2.Win.UltraWinGrid.v10.1~Infragistics.Win.UltraWinGrid.SummarySettingsCollection~Add(String,SummaryType,ICustomSummaryCalculator,UltraGridColumn,SummaryPosition,UltraGridColumn).html