this.sfDataGrid1.CellRenderers.Remove("TableSummary");
this.sfDataGrid1.CellRenderers.Add("TableSummary", new CustomGridTableSummaryRenderer(this.sfDataGrid1));
public class CustomGridTableSummaryRenderer : GridTableSummaryCellRenderer
{
public CustomGridTableSummaryRenderer(SfDataGrid dataGrid)
{
IsEditable = true;
DataGrid = dataGrid;
}
protected SfDataGrid DataGrid { get; set; }
protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
{
if(((DataGrid.View.Records.Count+ DataGrid.TableSummaryRows.Count)) == rowColumnIndex.RowIndex)
{
var summary1 = (SummaryCreator.GetSummaryDisplayText(DataGrid.View.Records.TableSummaries[0], "Quantity" , DataGrid.View));
var summary2 = SummaryCreator.GetSummaryDisplayText(DataGrid.View.Records.TableSummaries[0], "UnitPrice", DataGrid.View);
summary1 = summary1.Replace("$", "");
summary2 = summary2.Replace("$", "");
if (string.IsNullOrEmpty(cellValue))
return;
NumberFormatInfo format = new NumberFormatInfo();
cellValue = (Convert.ToDouble((Convert.ToDouble(summary1) - Convert.ToDouble(summary2)))).ToString();
StringFormat stringFormat = new StringFormat();
stringFormat.LineAlignment = StringAlignment.Center;
stringFormat.Alignment = StringAlignment.Center;
paint.DrawString(cellValue, style.Font.GetFont(), Brushes.Black, cellRect, stringFormat);
}
else
base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex);
}
} |