• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5667
  • Last Modified:

Changing summary value for UltraWinGrid

I am using ultrawingrid which summary enabled showing the sum of the column. Now I want to make the summary value to zero and it should show only tthe sum of those rows which i select using check box.
0
srikanthreddyn143
Asked:
srikanthreddyn143
  • 4
1 Solution
 
ZeonFlashCommented:
The summary value in a column is a read-only property, so you can't just force it to be a value.  Instead, you can create a custom summary calculator.

The following example assumes you have a column "Selected" (boolean) and a column "ValueColumn" (decimal).  After you check/uncheck the Selected cell, it will automatically re-calculate the summary (if it's in view)
	Private Class MyCustomSummarySettings
		Implements ICustomSummaryCalculator
 
		Private decTotal As Decimal = 0.0
 
		Public Sub New()
		End Sub
 
		'Reset the summary total
		Private Sub BeginCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.BeginCustomSummary
			decTotal = 0
		End Sub
 
		'Perform the summary 
		Private Sub AggregateCustomSummary(ByVal summarySettings As SummarySettings, ByVal row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary
			If Not row.Cells("Selected").Value Then Exit Sub
 
			Try
				decTotal += Convert.ToDecimal(row.GetCellValue(summarySettings.SourceColumn))
			Catch ex As Exception
				MsgBox("Error converting cell value to decimal", MsgBoxStyle.Critical)
			End Try
		End Sub
 
		'Return the summary value
		Private Function EndCustomSummary(ByVal summarySettings As SummarySettings, ByVal rows As RowsCollection) Implements ICustomSummaryCalculator.EndCustomSummary
			Return decTotal
		End Function
	End Class
 
	Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout
		Dim summary As Infragistics.Win.UltraWinGrid.SummarySettings
 
		'Create a new summary object for the band
		summary = UltraGrid1.DisplayLayout.Bands(0).Summaries.Add("CustomSummary")
 
		summary.SummaryType = SummaryType.Custom
		summary.SourceColumn = UltraGrid1.DisplayLayout.Bands(0).Columns("ValueColumn")
		summary.CustomSummaryCalculator = New MyCustomSummarySettings
	End Sub

Open in new window

0
 
srikanthreddyn143Author Commented:
Hi Zeon,

Thanks for your reply.It was throwing an exception "Cannot convert 'True' to Long" when i used code in this way.

 'Perform the summary 
    Private Sub AggregateCustomSummary(ByVal summarySettings As SummarySettings, ByVal row As UltraGridRow) Implements ICustomSummaryCalculator.AggregateCustomSummary
        Try
            If Not row.Cells("CB").Value.ToString Then
                Exit Sub
            Else
                decTotal += Convert.ToDecimal(row.Cells("Amount").Value)
            End If
        Catch ex As Exception
            ExceptionManager.Publish(ex)
        End Try
    End Sub

Open in new window

0
 
srikanthreddyn143Author Commented:
It was throwing exception At line "If Not row.Cells("CB").Value"
0
 
srikanthreddyn143Author Commented:
Thanks.
Its working fine when i kept "If Not row.Cells("CB").Value = "True" Then ". But how can I have the summary as a footer. Right now it is scrolling with the datagrid.
0
 
srikanthreddyn143Author Commented:
Thank you. Thats fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now