Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Set the cell format with a string editor
posted

I want to give my users the ability to type an expression when editing a cell. I will then evaluate that expression and set the cell value to a numeric value. My columns will always be numeric. So I basically want the same behavior as Excel where a user can enter '=5+2' and 7 will appear. I have the evaluation portion working, but I cannot set the cell format. The cell shows '7.0000000' and I just want 7.00.

var numberEditorStyle = new Style(typeof(XamNumericEditor));
numberEditorStyle.Setters.Add(new Setter(XamNumericEditor.FormatProperty, "0.00"));

DataTable.FieldLayouts[0].Fields[0].DataType = typeof(double);

DataTable.FieldLayouts[0].Fields[0].EditAsType = typeof(string); 
DataTable.FieldLayouts[0].Fields[0].Settings.EditorStyle = numberEditorStyle;

Alternatively I could try not setting the EditAsType to typeof(string) and the formatting looks correct, but if I do not, the user can only enter numeric characters and cannot enter '=5+2'.