2016-06-14 64 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; 
    } 
}