You are not logged in.
This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.
Pages: 1
Topic closed
Hi Jing,
In this version, the IDataFormatter is working. Thanks.
In the documentation that you provided, you use GetData<double> to get the value as a number and to convert it. It works the first time (value set by code) but if the user change the value, the internal Data member of the cell returns to a string and GetData<double>() returns 0 (even if the user types only figures).
I had to convert it manually to a numeric value.
If the setting of Edit_AutoFormatCell is false, then it doesn't work even the first time because the Custom DataFormatter isn't called at all.
private void Form1_Load(object sender, EventArgs e)
{
Worksheet ws = grid.Worksheets[0];
unvell.ReoGrid.DataFormat.DataFormatterManager.Instance.DataFormatters.Add(unvell.ReoGrid.DataFormat.CellDataFormatFlag.Custom, new MyDataFormatter());
// This, if uncommented, disables the Custom format
//ws.SetSettings(unvell.ReoGrid.WorksheetSettings.Edit_AutoFormatCell, false);
ReoGridCell cell = ws.Cells[1, 1];
cell.DataFormat = unvell.ReoGrid.DataFormat.CellDataFormatFlag.Custom;
cell.DataFormatArgs = "SecondToTime";
cell.Data = 1200;
cell = ws.CreateAndGetCell(1, 2);
cell.DataFormat = unvell.ReoGrid.DataFormat.CellDataFormatFlag.Custom;
cell.DataFormatArgs = "SecondToTime";
}
}
class MyDataFormatter : unvell.ReoGrid.DataFormat.IDataFormatter
{
public string FormatCell(ReoGridCell cell)
{
// This doesn't work
double val = cell.GetData<double>();
// This works
double val2 = 0;
unvell.ReoGrid.Utility.CellUtility.TryGetNumberData(cell.Data, out val2);
// This works also (without test for incorrect entry)
double val1 = double.Parse(cell.Data.ToString());
var df = cell.DataFormatArgs;
if (df != null)
{
if (df is string)
{
switch (df as string)
{
case "SecondToTime":
{
// doesn't handle the incorrect values
return new TimeSpan(0, 0, (int)val1).ToString();
break;
}
}
}
}
return val1 < 0 ? string.Format("[{0}]", (-val1).ToString("###,###,##0.00")) : val1.ToString("###,###,###.00");
}
public bool PerformTestFormat()
{
return true;
}
}
Fortunately, there is a workaround
Best regards
Eric
Offline
Hi Eric,
Thanks for the information, and very nice sample.
The Cell.GetData<double> method would be fixed in next release.
Regards, Jing
Offline
This problem has been fixed in 0.8.9.2. Thanks for report.
Offline
Pages: 1
Topic closed