hi
I have sfdatagrid has a column (numeric column) but the values in that column:
10.5
10.55
10.555
0.000067
but the data appear as following values:
10.50
10.55
10.56
0.00
How to solve this problem??
I want to keep the value and show it as it is coming from the database in each row.
Hi Mohamad ,
We have analyzed your query, and we understand your requirement. It can be achieved by setting the Format property of the GridNumericColumn to display the values without rounding. For example, you can use "0.###" as the format to display up to three decimal places without rounding. We have provided the sample for your reference . Kindly review the sample and let us know if you have any concerns on this .
Image Reference :
|
|
thank you, it's working now but when I try to edit the number via SfDatagrid directly I can't write more than 2 decimal value!! why? how can I solve the problem?
Mohamad ,
We have analyzed your query, and your reported issue is related to our dependency control. We have checked with the concerned team, and we need time to validate this . We will update further details on September 15,2023.
Mohamad ,
We have analyzed your query, and your requirement can be achieved by customizing the GridNumericCellRenderer and changing the SfNumericTextBox validation mode to 'LostFocus'. We have provided the sample for your reference . Kindly review the sample and let us know if you have any concerns on this.
Code Snippet :
|
this.sfDataGrid.CellRenderers.Add("Numeric", new
GridNumericCellCellRendererExt()); { protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement) {
base.OnInitializeEditElement(column, rowColumnIndex, uiElement); uiElement.ValidationMode = Syncfusion.WinForms.Input.Enums.ValidationMode.LostFocus; } }
|
thanks, but when I write the value I see there is "00" in the last of the number (during the writing) how can hide that 00 when writing?
Mohamad,
Your requirement to hide the trailing zeros in the GridNumericColumn can be
achieved by enabling the HideTrailingZeros property in the loaded edit element
of SfNumericTextBox. Refer to the below code snippet,
|
//Remove existing Numeric Renderer this.sfDataGrid.CellRenderers.Remove("Numeric"); //Add customized Numeric Renderer this.sfDataGrid.CellRenderers.Add("Numeric", new GridNumericCellCellRendererExt());
//Custom cell renderer to customize the SfNumericTextBox public class GridNumericCellCellRendererExt : GridNumericCellRenderer { // Override the OnInitializeEditElement method to customize the SfNumericTextBox protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement) { base.OnInitializeEditElement(column, rowColumnIndex, uiElement); //Hide the trailing zeros uiElement.HideTrailingZeros = true; uiElement.ValidationMode = ValidationMode.LostFocus; } } |
Find the sample demo in the attachment.
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
when I applied your solution I got the error that I you can see in attachment video.
Hi Mohamad,
We were not clear with your reported error, and we can’t get this from attached video. Furthermore, we reviewed the provided sample, and it appeared to function as expected. To assist us in resolving your query, please provide additional details regarding the specific error you encountered. This information will be invaluable in helping us address your issue effectively.
Regards,
Santhosh.G