Editing Numeric without Decimals

Hi!

I'm trying to set my Numeric columns to allow edition without decimals. The grid shows the numbers as integers (since I set it within each field properties), but when the user edits the field, the number within changes to 2-decimals mode.

I tried using:

Dim numberFormat As Globalization.NumberFormatInfo = TryCast(Application.CurrentCulture.NumberFormat.Clone(), Globalization.NumberFormatInfo)

but I cannot see where I may put this info!

I appreciate any help to solve it.



17 Replies

SS Susmitha Sundar Syncfusion Team June 23, 2020 01:29 PM UTC

Hi DavidBS, 
 
Thank you for using Syncfusion controls. 
 
You can achieve your requirement “Need to update the cell without decimal value” by setting NumericFormatInfo for GridNumericColumn. Please refer the below UG link: 
 
 
  
Dim numberFormat As NumberFormatInfo = TryCast(Application.CurrentCulture.NumberFormat.Clone(), NumberFormatInfo) 
numberFormat.NumberDecimalDigits = 0 
numberFormat.NumberDecimalSeparator = "*" 
numberFormat.NumberGroupSizes = New Integer() { } 
Me.sfDataGrid1.Columns.Add(New GridNumericColumn() With {.HeaderText = "Quantity", .MappingName = "Quantity", .FormatMode = FormatMode.Numeric, .NumberFormatInfo = numberFormat }) 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Susmitha S 
 



DA DavidBS June 23, 2020 01:37 PM UTC

Thanks Susmitha, but I cannot create the columns at the runtime.

I need to set the numeric format as a property or something like this.




SS Susmitha Sundar Syncfusion Team June 25, 2020 01:37 AM UTC

Hi DavidBS, 
 
Thank you for the update. 
 
If you generate the columns by AutoGenerateColumns then you can set the NumericPropertyInfo property in SfDataGrid.AutoGeneratingColumn event. 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Susmitha S 



DA DavidBS June 25, 2020 12:42 PM UTC

Hi Susmitha,

Thanks, but I don't have the NumericFomat property available neither in the "e.Column" nor in "e.Column.CellStyle" and so forth.

The code is:

     Private Sub AutoGeneratingColumn(ByVal sender As Object, ByVal e As AutoGeneratingColumnArgs)

If e.Column.MappingName = "OrderID" Then
e.Column.   ????????
End If
End Sub



Let me explain a little bit deeper:

- The grid was created at design-time.
- I can change any properties there (in Design-mode) but I can't see any property there to solve this problem.
- The decimals only appear when user edit the cell.

I guess there is no solution.



MA Mohanram Anbukkarasu Syncfusion Team June 26, 2020 09:07 AM UTC

Hi David, 

Thanks for the update.  

The NumberFormatInfo property will be available in the GridNumericColumn class. You can achieve this by casting the argument e.Column in AutoGeneratingColumn event to GridNumericColumn as shown in the following code example. 

Code example :  

AddHandler sfDataGrid1.AutoGeneratingColumn, AddressOf OnSfDataGrid1_AutoGeneratingColumn 
 
Private Sub OnSfDataGrid1_AutoGeneratingColumn(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs) 
       If e.Column.MappingName = "UnitPrice" Then 
              TryCast(e.Column, GridNumericColumn).NumberFormatInfo = New System.Globalization.NumberFormatInfo() With {.NumberDecimalDigits = 0} 
       End If 
End Sub 

Note : The AutoGeneratingColumn event should be triggered before assigning the DataSource. 

We have created a simple sample using the above code example and it is available in the following link for your reference. 


Please let us know if you require further assistance from us. 

Regards, 
Mohanram A. 



DA DavidBS June 30, 2020 04:22 AM UTC

Hi Mohanram,

Thanks for your help but I had no success at all.
Curiously, this event in not even called!

The AutoGenerateColumns proptery if false but even changing it to true has no effect too.

Kind regards,
David






SS Susmitha Sundar Syncfusion Team July 1, 2020 12:48 PM UTC

Hi David,  
 
Thanks for the update.   
 
We suspect that you are raise the AutoGeneratingColumn event after setting the SfDataGrid.DataSource.  but should raise the event before setting the DataSource. 
 
 
Public Sub New() 
              InitializeComponent() 
              AddHandler sfDataGrid1.AutoGeneratingColumn, AddressOf OnSfDataGrid1_AutoGeneratingColumn 
              sfDataGrid1.DataSource = New OrderInfoCollection().OrdersListDetails 
End Sub 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Susmitha S 



DA DavidBS July 2, 2020 12:40 PM UTC

Hi Susmitha!

Thanks for your addendum but no, the problem persists.

Let me explain what I'm doing here:

1) The grid was set at design-mode - it's easier to set a lot of properties...

2) I created a collection to fill the fields

Private _Pages As New ObservableCollection(Of PDF_Pages2Sign)
Public Property Pages() As ObservableCollection(Of PDF_Pages2Sign)
Get
Return _Pages
End Get
Set(ByVal value As ObservableCollection(Of PDF_Pages2Sign))
_Pages = value
End Set
End Property



That collection see a new class of fields, as shown below:


Public Class PDF_Pages2Sign

Private _Pagina As Integer
Private _Vertical As Integer
Private _Horizontal As Integer
Private _Tipo As String


Public Property Pagina As Integer
Get
Return _Pagina
End Get

Set(ByVal value As Integer)
_Pagina = value
End Set
End Property

Public Property Horizontal As Integer
Get
Return _Horizontal
End Get

Set(ByVal value As Integer)
_Horizontal = value
End Set
End Property


Public Property Vertical As Integer
Get
Return _Vertical
End Get

Set(ByVal value As Integer)
_Vertical = value
End Set
End Property



Public Property Tipo As String
Get
Return _Tipo
End Get

Set(ByVal value As String)
_Tipo = value
End Set
End Property



Public Sub New(ByVal pg As Integer, ByVal hor As Integer, ByVal vert As Integer, ByVal Tp As String)
Me.Pagina = pg
Me.Horizontal = hor
Me.Vertical = vert
Me.Tipo = Tp
End Sub

End Class


3) As recommended, I put the Handler into NEW event

Public Sub New()
' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
AddHandler SignaturesGrid.AutoGeneratingColumn, AddressOf OnSignaturesGrid_AutoGeneratingColumn
End Sub


4) The "TIPO" field (COMBO type) is populated and the Renderer is set as recommended by documentation:


               Dim TiposAssinaturas As New Dictionary(Of String, String)

TiposAssinaturas.Clear()
TiposAssinaturas.Add("T", "T")
TiposAssinaturas.Add("TL", "TL")
TiposAssinaturas.Add("Q", "Q")
TiposAssinaturas.Add("QL", "QL")
TiposAssinaturas.Add("M", "M")
TiposAssinaturas.Add("ML", "ML")

TryCast(Me.SignaturesGrid.Columns("Tipo"), Syncfusion.WinForms.DataGrid.GridComboBoxColumn).MappingName = "Tipo"
TryCast(Me.SignaturesGrid.Columns("Tipo"), Syncfusion.WinForms.DataGrid.GridComboBoxColumn).DataSource = New BindingSource(TiposAssinaturas, Nothing)
TryCast(Me.SignaturesGrid.Columns("Tipo"), Syncfusion.WinForms.DataGrid.GridComboBoxColumn).DisplayMember = "Key"
TryCast(Me.SignaturesGrid.Columns("Tipo"), Syncfusion.WinForms.DataGrid.GridComboBoxColumn).ValueMember = "Value"

Me.SignaturesGrid.CellRenderers.Remove("Tipo")
Me.SignaturesGrid.CellRenderers.Add("Tipo", New GridComboBoxCellRendererExt())



5) The datasource is populated during the processing

Dim Item As New PDF_Pages2Sign(Local_da_Assinatura_Pagina, Local_da_Assinatura_Coordenada_X, Local_da_Assinatura_Coordenada_Y, Setagem)
Pages.Add(Item)
SignaturesGrid.DataSource = Pages

                    (see topic 2 above for the definition of PDF_Pages2Sign



So, following the above code, everything functions 100%, except the "edition mask", which at the integers fields always shows 2 decimals. Even I setting the field to "{0:n0}" at design-mode (which will be expected to function) or either at runtime mode.

And I checked that even using the Handler at NEW event, the method is not called anyway.

It's really weird...  :)

I appreciate your attention.

Kindest regards,
David





SS Susmitha Sundar Syncfusion Team July 3, 2020 03:05 PM UTC

Hi David, 
 
Thank you for the update. 
Based on the provided information, we have checked the mentioned issue “AutoGeneratingColumn event not raised” and we unable to replicate the issue from our end, it is working fine as expected. We have prepared sample based on your code snippet, 

 
We have tested with Syncfusion version 18.1.0.52. 
 
Please check our provide sample and let us know, if you still facing the same issue? If not, please modify the sample based on your scenario. 
 
It will be helpful for us to check on it and provide you the solution at the earliest.   
 
Regards,
Susmitha S




DA DavidBS July 3, 2020 04:07 PM UTC

Hi Susmitha,

Thank you - I'll see the code later, during the weekend. I have a lot of things to solve and provide here.

See you on Monday.

Kindest regards,
David


MA Mohanram Anbukkarasu Syncfusion Team July 6, 2020 09:26 AM UTC

Hi David, 

Thank for the update.  

We will wait to hear from you. 

Regards, 
Mohanram A. 



DA DavidBS July 6, 2020 06:18 PM UTC

Hi Susmitha,

I think the problem is focused at the FIELD creation. In your sample, you create all field at the runtime - a procedure conflictant with the same procedure at the design-time.

If you have an empty grid and, before anything, you create the fields setting its properties like shown in that thread, everything functions ok... But, if you already have the field created in the grid at the Design-Time, the property cannot be accessed anymore OR it's ineffective.

Anyway, thanks for your attention and efforts.

Kindest regards,
David







MA Mohanram Anbukkarasu Syncfusion Team July 7, 2020 03:11 PM UTC

Hi David, 
 
Thanks for the update. 
 
We are little bit unclear with your update. If the DataSource is assigned in the designer itself before adding handler for the AutoGeneratingColumn event, the event will not be triggered. If possible could you please modify the sample from the following link based on your scenario. It will be helpful for us to provide a prompt solution without further delay. 
 
 
Regards, 
Mohanram A. 



DA DavidBS July 7, 2020 07:28 PM UTC

No....

Just the GRID and its FIELDS are set in design-mode. Using Properties - Columns..

As shown above, the datasource is linked at runtime, during the LOAD event.

Kindest regards
David



MA Mohanram Anbukkarasu Syncfusion Team July 8, 2020 09:39 AM UTC

Hi David, 

Thanks for the update. 

It is hard for us to provide exact solution for your issue without getting any code snippets/sample from you. From the provided details we suspect that you are adding the columns manually to the DataGrid using the SfDataGrid.Columns collection. The AutoGeneratingColumn event will be raised only when the column is auto generated. It will never raise for the columns which are manually added. 

For that the SfDataGrid.AutoGenerateColumns property value should be set to true  before assigning the DataSource and the event should be triggered before assigning the DataSource. Kindly ensure this in your application. If the issue still exists kindly provide the code snippets you have used to create the Grid and Fields in design mode and the code snippet to set DataSource. If possible please replicate the issue in any simple sample and revert to us. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution without further delay. 

Regards, 
Mohanram A. 



DA DavidBS July 10, 2020 11:11 PM UTC

Thanks Mohanram.

I will try to create a simple project to demonstrate what I'm saying and that is very, very simple:

- create a grid on a form.
- create its fields in design mode.
- create the datasource using the mapping field names

That's it.
Anyway, I understand and agree that demonstrating it with a project is really better.

See you very soon.
Kindest regards,
David





MA Mohanram Anbukkarasu Syncfusion Team July 13, 2020 11:56 AM UTC

HI David, 

Thanks for the update.  

You have mentioned to create the DataGrid fields in design mode in this update. As we mentioned in our previous update, the AutoGeneratingColumn event will be raised only when the columns are auto generated. It will never raise for the columns which are manually added to the SfDataGrid.Columns collection. 

We will wait for the update with demo project.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon