在DevExpress网格中计算


威斯特
2025-03-08 07:51:45 (14小时前)
  1. 我有一个DevExpress



</跨度>
在Windows窗体中,其数据源是动态的,并在运行时获取绑定。我需要有一些

计算
</跨度>
要做到这一点


</跨度>

所有列都是动态的

让我们说


</跨度>
有2列产品和速率300行。
在这里,我需要第三栏,比如说。最高费率。

该列的第一个单元格应该是从第1个5行开始的最大速率
见下文excel example的例子

2 条回复
  1. 0# 坚挺的阿袁 | 2019-08-31 10-32



    使用gridview的CustomDrawCell事件。




    1. private void gridview_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
      {
      //assume colMaxRate is your Max Rate column name
      if (e.Column.FieldName == colMaxRate.FieldName) {
      //do your calculation you need, in this example, find max value of next 4 rows including current row
      int maxValue = 0;
      //initialize maxValue to current row’s value
      maxValue = gridview.GetRowCellValue(e.RowHandle, colRate.FieldName);
      for (rowIndex = 0; rowIndex < 4; rowIndex++) {
      //TODO: do your own checking to make sure you don’t exceed last row count
      if (maxValue > gridview.GetRowCellValue(e.RowHandle + rowIndex, colRate.FieldName)) {
      maxValue = gridview.GetRowCellValue(e.RowHandle + rowIndex, colRate.FieldName);
      }
      }
      e.DisplayText = maxValue.ToString();
      e.Handled = true;
      }
      }

    2. </code>

登录 后才能参与评论