如何在Infragistics Ultrawingrid中获得时间摘要?

时间:2015-03-02 21:24:29

标签: vb.net infragistics ultrawingrid

我有一个infragistics ultrawingrid,其中我有一个时间列,小时和分钟。我想总结专栏,以便我可以获得旅行的总时间。旅程的每一段都有自己的排。我试过了;

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


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

这不起作用,因为摘要行需要使用整数。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您没有告诉您的时间列实际是什么类型,但一般的解决方案是创建自己的ICustomSummaryCalculator来处理您的数据。

该文档提供了example implementation,但此处是TimeSpan列的实现:

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

像这样使用:

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