vb.netinfragisticsultrawingrid

How do I get a summary of time in Infragistics Ultrawingrid?


I have the Infragistics UltraWinGrid in which i have a time column, hours and minutes. I want to summary the column so that I can get a total time of the trip. Each leg of the trip has its own row. I have tried:

Dim SumTripDuration As SummarySettings = .Summaries.Add(SummaryType.Sum, .Columns("LegDuration"), SummaryPosition.UseSummaryPositionColumn)

SumTripDuration.DisplayFormat = "{0}"
SumTripDuration.Appearance.TextHAlign = HAlign.Right

This doesn't work because the summary row needs to use integers. Any help would be greatly appreciated.


Solution

  • You didn't tell what the type of your time column actually is, but a general solution is to create your own ICustomSummaryCalculator which can handle your data.

    The documentation gives an example implementation, but here's a implementation for a TimeSpan column:

    Class TimeSummary
        Implements ICustomSummaryCalculator
    
        Dim _totals As New TimeSpan(0)
        Dim _columnname As String
    
        Public Sub New(columnName As String)
            _columnname = columnName
        End Sub
    
        Public Sub BeginCustomSummary(summarySettings As SummarySettings, rows As RowsCollection) Implements ICustomSummaryCalculator.BeginCustomSummary
            _totals  = New TimeSpan(0)
        End Sub
    
        Public Sub AggregateCustomSummary(summarySettings As SummarySettings, row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary
            Dim time = row.GetCellValue(summarySettings.SourceColumn.Band.Columns(_columnname))
    
            If TypeOf time Is DBNull Then
                Return
            End If
    
            _totals += TimeSpan.Parse(time.ToString())
        End Sub
    
        Public Function EndCustomSummary(summarySettings As SummarySettings, rows As RowsCollection) Implements ICustomSummaryCalculator.EndCustomSummary
            Return _totals 
        End Function
    End Class
    

    Use it like this:

    Dim timecolumn = grid.DisplayLayout.Bands(0).Columns("Time")
    grid.DisplayLayout.Bands(0).Summaries.Add(SummaryType.Custom, New TimeSummary(timecolumn.Key), timecolumn, SummaryPosition.UseSummaryPositionColumn, timecolumn)