我有一个分组网格控件,其中包含group sum,summarytype:custom。我希望有以下内容:如果用户选择或取消选择一行,相应的组摘要也会更改。我还只需要所选行的总和。
我有这段代码:
Private Sub gvUtalhatok_CustomSummaryCalculate(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryEventArgs) Handles gvUtalhatok.CustomSummaryCalculate
Dim View As GridView = CType(sender, GridView)
If e.SummaryProcess = CustomSummaryProcess.Start Then custom_sum = 0
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
For i = 0 To View.GetSelectedRows.Count - 1
custom_sum += Convert.ToDecimal(View.GetRowCellValue(View.GetSelectedRows(i), "BRUTTO"))
Next
'custom_sum += Convert.ToDecimal(e.FieldValue)
End If
If e.SummaryProcess = CustomSummaryProcess.Finalize Then e.TotalValue = custom_sum
End Sub
而且:
Private Sub gvUtalhatok_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs) Handles gvUtalhatok.SelectionChanged
gvUtalhatok.UpdateGroupSummary()
End Sub
问题是,如果我选择一行,我得到列总和的三倍,所有组行显示相同的总和值。
如何修改代码以显示正确的和值,仅针对组行,选择哪些行?
感谢。
答案 0 :(得分:0)
您应该从CustomSummaryCalculate事件处理程序中删除循环。而是使用以下代码:
Private Sub gvUtalhatok_CustomSummaryCalculate(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryEventArgs) Handles gvUtalhatok.CustomSummaryCalculate
Dim View As GridView = CType(sender, GridView)
If e.SummaryProcess = CustomSummaryProcess.Start Then custom_sum = 0
If e.SummaryProcess = CustomSummaryProcess.Calculate Then
if View.IsRowSelected(e.RowHandle) then
e.TotalValue = Convert.ToDecimal(e.TotalValue) +
Convert.ToDecimal(View.GetRowCellValue(e.RowHandle, "BRUTTO"))
End If
End If
End Sub