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'.
I got it to work. I had to remove the EditAsType line
DataTable.FieldLayouts[0].Fields[0].EditAsType = typeof(string);
When I did that and used the XamTextEditor instead of the XamNumericEditor, that fixed it.
This is what the working code looks like:
var numberEditorStyle = new Style(typeof(XamTextEditor));
numberEditorStyle.Setters.Add(new Setter(XamTextEditor.FormatProperty, "0.00"));
DataTable.FieldLayouts[0].Fields[0].DataType = typeof(double);DataTable.FieldLayouts[0].Fields[0].Settings.EditorStyle = numberEditorStyle;
Can you post a sample so I can see what is going on?
Unfortunately that didn't make a difference.
Hi Jason,
I think that you are better off using a XamTextEditor for this scenario instead of a XamNumericEditor. Try setting the EditorType to XamTextEditor or, if you are creating the Field in XAML, use a TextField instead of a Field.