作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 xtraGrid gridControl 中添加自定义 summerType?
我想将 SummerItem
添加到我的 xtraGrid gridControl
中名为 total percent
的列,它将计算其他两个的百分比列。
我总共有 3 列1. A项数量2. 总数量和3.百分比
我还有 summaryItems
和
1. Sum of column 1 (`Quantities of Item A`)
2. Sum of column 2 (`Total Quantities`) and
3. Total Percentage whitch I would like to make a divition with ( column 1 / column 2 ) * 100
我的问题是我该怎么做?我应该使用 Custom Summary Type
吗?如果是,如何使用这种类型?
谁能帮帮我?
谢谢
最佳答案
非常适合我
我在我的类中创建了两个私有(private)变量
private decimal _sumOfValues = 0;
private decimal _sumOfTotalValue = 0;
在百分比列中创建了一个自定义摘要类型
,并在选项 Tag
中键入了 percentageColumnCustomSummary
,这是该摘要列的 ID
在我的 xtraGrid 上创建一个事件
private void allocationGridView_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e)
然后输入下面的代码
private void allocationGridView_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e)
{
try
{
//int summaryID = Convert.ToInt32((e.Item as GridSummaryItem).Tag);
string summaryTag = Convert.ToString((e.Item as GridSummaryItem).Tag);
GridView View = sender as GridView;
// Initialization
if (e.SummaryProcess == CustomSummaryProcess.Start) {
_sumOfValues = 0;
_sumOfTotalValue = 0;
}
//Calculate
if (e.SummaryProcess == CustomSummaryProcess.Calculate) {
decimal colValueColumnValue = Convert.ToDecimal( View.GetRowCellValue(e.RowHandle, "Value") );
decimal colTotalValueColumnValue = Convert.ToDecimal( View.GetRowCellValue(e.RowHandle, "TotalValue") );
switch (summaryTag) {
case "percentageColumnCustomSummary":
_sumOfValues += colValueColumnValue;
_sumOfTotalValue += colTotalValueColumnValue;
break;
}
}
// Finalization
if (e.SummaryProcess == CustomSummaryProcess.Finalize) {
switch (summaryTag) {
case "percentageColumnCustomSummary":
e.TotalValue = 0;
if (_sumOfTotalValue != 0) {
e.TotalValue = (_sumOfValues / _sumOfTotalValue);
}
break;
}
}
}
catch (System.Exception ex)
{
_logger.ErrorException("allocationGridView_CustomSummaryCalculate", ex);
}
}
这很好用!
关于c# - xtraGrid gridControl 中的自定义 summerType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23496771/
如何在 xtraGrid gridControl 中添加自定义 summerType? 我想将 SummerItem 添加到我的 xtraGrid gridControl 中名为 total perc
我是一名优秀的程序员,十分优秀!