I am using Xamdatagrid which is bound to some data. Currently the grid shows around 8 digits after decimal, What I want is that when I click the cell for edit mode it should show only 4 digits after decimal but it should not limit me when I try and enter digits.
For example: If the value is 14.52648 it should display 14.5264 but when I click and start editing it should allow me so while editing the cell will look like 14.526489561
I am using 15.1.20151.2008
Hi,
First approach doesn't seem to work. I am setting these properties in code behind.
Can you help me with some small application?
Hello Neelesh, Based on the description you have provided that when the double value of your DataItem is 16.15678945, the DisplayText is 16.1567 and the value in edit mode is also 16.1567, I presume you have used the second approach from my previous reply. If this is the case, this behavior is expected since every time the editor enters edit mode, it rounds up the actual value up to four digits after the decimal point. In order to prevent the rounding of the value in edit mode and keep it 16.15678945, I can suggest you try the first approach I have introduced in my previous reply. If you require any further assistance on the matter, please let me know.
Hi Tacho,
Thanks for your help.This has worked for me, but raised another issue.
If on my grid I show only 4 digits then while saving only 4 digits are saved.
Let's say if my value is 16.15678945, then on UI I show only 16.1567 so while saving only the later value is saved while I want to save 16.15678945.
Kindly help me through.
Hello Neelesh, In order to visualize the values as you have described, I can suggest you a couple of approaches depending on the exact scenario. Both will visualize the display value (when not in edit mode) with a maximum of 4 digits after the decimal point. When in edit mode, the PromptChars and the trailing fractional zeros will not be visualized.1) The value in edit mode will be visualized with the rest of the digits with the option to include more if there is enough space (based on the mask).<Style x:Key="valueConverterStyle" TargetType="{x:Type igEditors:XamNumericEditor}"> <Setter Property="Mask" Value="{}{double:4.8}" /> <Setter Property="Format" Value="0.####" /> <Setter Property="TrimFractionalZeros" Value="True" /> <Setter Property="PromptChar" Value="" /></Style> 2) When entering edit mode, the value will be cut and rounded up to four digits after the decimal point with the option to include more if there is enough space (based on the mask). The new value will be cut and rounded up as well the next time the editor enters edit mode. <Style x:Key="valueConverterStyle" TargetType="{x:Type igEditors:XamNumericEditor}"> <Setter Property="Mask" Value="{}{double:4.8}" /> <Setter Property="Format" Value="0.####" /> <Setter Property="TrimFractionalZeros" Value="True" /> <Setter Property="PromptChar" Value="" /> <EventSetter Event="EditModeStarting" Handler="XamNumericEditor_EditModeStarting" /></Style> void XamNumericEditor_EditModeStarting(object sender, EditModeStartingEventArgs e){ var editor = (sender as XamNumericEditor); editor.Value = Math.Round(((double)editor.Value), 4);} If you require any further assistance on the matter, please let me know.
Unfortunately this doesn't seems to work.
Setting <Setter Property="Format" Value="###.0000" /> means that even if the value has not fraction part the grid still shows 0s. i.e 684 is now shown as 684.0000 which is not what I want, so for Format property 0.#### is apt as it shows what I need.
The issue is when I enter the edit mode. What I want is if my value is 54.56328745, then while editing I want to show the value as 54.5632 and also allow the user to enter more digits agter the decimal. This would mean the user can see 54.5632 but can change the value to 54.56323265.