2016-06-14 65 views
0

我有一个DevExpress网格在Windows窗体中,其数据源是动态的,并在运行时获取绑定。我需要在这个网格上进行一些计算。在DevExpress网格计算

的所有列都是动态

咱们说网格是有2列产品与300行速率。 在这里,我需要第三列让我们说,例如。最大利率。

这一列的第一个单元格应该是最大速率从第5行开始 查看以下excel示例。

enter image description here 这MAX RATE列可以是任何东西(可能是平均值或和或任何东西)

任何帮助,将不胜感激。

+0

@FirstStep 不能,它的简单Windows窗体应用程序与DevExpress控件。 –

回答

0

使用gridview的CustomDrawCell事件。

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; 
    } 
}