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
Hello Neelesh, In order to display only 4 digits after the decimal point, an approach I can suggest you is to create a Style that is targeting the XamNumericEditor in the Resources of the XamDataGrid. Afterwards by setting the Format property of the editor to "###.0000" and reference it from the respective Field, you should be able to achieve the desired effect. <igDP:XamDataGrid.Resources> <Style x:Key="numericStyle" TargetType="{x:Type igEditors:XamNumericEditor}"> <Setter Property="Mask" Value="{}{double:4.8:c}" /> <Setter Property="Format" Value="###.0000" /> </Style></igDP:XamDataGrid.Resources> <igDP:NumericField Name="Price" EditorStyle="{StaticResource numericStyle }">Since the Mask property works directly with the Value of the editor, the PromptChars and the trailing zeros will be visible while the editor is in edit mode. If you require any further assistance on this matter, please do not hesitate to ask.
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.
Hello Neelesh, I have prepared a sample application where I create a Style for the XamNumericEditor either directly in XAML or in the Click event of a Button by manually setting it to the Field's EditorStyle property. If the issue is still reproduced or this is not the behavior you were looking for, feel free to modify the sample so the issue is reproduced and send it back to me for further investigation.
Hi Tacho,
The problem still remains the same. In the grid (normal mode) the application shows only 4 digits but when I click on a cell and enter the edit mode it show more than that.
My requirement is that in normal mode and in edit mode I need to show 4 digits after decimal, but when I save the value I need entire value entered by the user.
I have seen this behaviour in UltraGrid.
Hello Neelesh,
By saying "save" I presume you mean updating the DataItem after edit mode has been exited.
Resetting the value of the editor by rounding it up to four digits after the decimal point in code-behind in the EditModeStarting event will instantly visualize the value up to four digits (while in edit mode). Since this has not been done through the UI, the respective Record and it's DataItem will not get updated with that new value and this way you will keep the desired visualization and the actual value.
If the user enters a new value or add digits to the previous one through the UI, the respective Recod and it's DataItem will get updated with the new value and next time the user enters edit mode, the behavior from above will apply.
This way you should be able to visualize up to four digits after the decimal point both in display mode and in edit mode, while the actual value of the Record can be reset as a result of a user interaction only.I have attached a sample application with this behavior implemented. Inside you will find a button, whose Click event will display the current actual values for all DataItems' Prices from the XamDataGrid's DataSource.
If you require any further assistance on this matter, please let me know.
Thanks for the help so far. I have another issue with the digits. Just like in XamDataGrid, the value changes on the arrow key press, I have reciprocated same behavior on Ctrl + Arrow key. All work fine but the issue is that while performing this action the cell shows more than the expected 4 digits. Also if I try to use the logic that was mentioned earlier then while saving I get 4 digits only.
Example:
My Data: 12.236589
Visible during normal or edit mode: 12.2365
Pressing Ctrl + Arrow: 12.236589
Requirement: Show: 12.2365/13.2365/14.2365 but while saving save 14.236589
I have attached sample application too.
Hello Neelesh, An approach I can suggest you in order to display a maximum of four digits after the decimal point when incrementing the value of the cell with "Ctrl + Arrow key" functionality you have introduced is to change the mask of the editor respectively. Inside the OnKeyUp event, by setting the mask of the XamNumericEditor to "{double:4.4}" prior to setting the Handled property to true, you should be able to achieve the desired behavior: var cvp = CellValuePresenter.FromCell(dataGrid.ActiveCell);var editor = Utilities.GetDescendantFromType(cvp, typeof(XamNumericEditor), true) as XamNumericEditor;editor.Mask = "{double:4.4}";By handling the EditModeEnded event of the XamDataGrid, you can safely change back the value of the Mask property of the XamNumericEditor: if (e.Cell.Field.Name == "Price"){ var editor = e.Editor as XamNumericEditor; editor.Mask = "{double:4.8}";} While the cell is in edit mode, the operations of entering more than 4 digits after the decimal point and incrementing the value with "Ctrl + Arrow key" will not be working simultaneously because of the difference in the Mask. I have prepared a sample application, where this behavior has been implemented. If you require any further assistance on the matter, please let me know.