我的应用程序中有一个页面,该页面应执行以下操作:加载数据,根据所有行计算页脚总和,然后当用户选择一行时,应用程序将重新计算选定的页脚总和行。但是我有一个问题,在选择一行时,它不会将总和更新为正确的值。相反,可以这么说,这将永远是“落后”。例如,默认情况下,第一行被选中,如果我随后选择了第二行,它仍将显示第一行的总和。如果选择第三行,它将把页脚总数更新为第二行总和。另外,我已经通过调试控制台检查了SelectedRows属性,它正确地返回并求和了值。只是不会用正确的值更新UI。
这是可重复的步骤:
FYI:InvalidateFooter
导致grid_CustomDrawFooterCell
被调用
代码如下:
private void gridInternalUnmatched_FocusedRowChanged (object aSender, FocusedRowChangedEventArgs aEventArgs)
{
gridInternalUnmatched.GridView.InvalidateFooter();
}
private void grid_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
DataRow row = null;
if (gridInternalUnmatched.Support.SelectedRowHandles.Any())
row = gridInternalUnmatched.Support.GetDataRow(gridInternalUnmatched.Support.SelectedRowHandles[0]);
decimal value = 0;
//Race condition?
switch (e.Info.SummaryItem.FieldName)
{
case "QuantityTradeDate":
value = gridInternalUnmatched.Support.SelectedDataRows.Sum(aX => (decimal)aX["QuantityTradeDate"]);
break;
case "MarketValue":
value = gridInternalUnmatched.Support.SelectedDataRows.Sum(aX => (decimal)aX["MarketValue"]);
break;
case "InitialNotional":
value = gridInternalUnmatched.Support.SelectedDataRows.Sum(aX => (decimal)aX["InitialNotional"]);
break;
default: throw new InvalidOperationException();
}
e.Info.DisplayText = value.ToString();
}