It is possible to format cell data using a custom cell data formatter. A cell data formatter is defined by the following interface:

public interface IDataFormatter
{
  // Return a formatted string for the specified cell
  string FormatCell(ReoGridCell cell);

  // Determines whether to check all unformatted cells
  bool PerformTestFormat(); // Usually needs to return true
}

Create a custom cell data formatter

To create a cell data formatter, create a class that implements the IDataFormatter interface:

class MyDataFormatter : IDataFormatter
{
  public string FormatCell(ReoGridCell cell)
  {
   double val = cell.GetData<double>();
   return val < 0 ? string.Format("[{0}]", (-val).ToString("###,###,##0.00")) : val.ToString("###,###,###.00");
  }

  public bool PerformTestFormat()
  {
    return true;
  }
}

To apply this formatter class:

DataFormatterManager.Instance.DataFormatters.Add(CellDataFormatFlag.Custom, new MyDataFormatter());

To use this formatter:

cell.DataFormat = CellDataFormatFlag.Custom;
cell.Data = 12345.6789;

247

Was this article helpful?