Different decimal places for each row in a radgridview

1 Answer 261 Views
GridView
George
Top achievements
Rank 1
Iron
George asked on 18 Aug 2021, 05:08 AM

        Dim colUnitPrice As GridViewDecimalColumn = TryCast(Me.grdProduct.Columns("UnitPrice"), GridViewDecimalColumn)
        colUnitPrice.DecimalPlaces = gintDecimalPlaces
        colUnitPrice.FormatString = "{0:N" + gintDecimalPlaces.ToString + "}"

 

How to set different decimal places for each row in a radgridview

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Aug 2021, 12:32 PM
Hello, George,

It is possible to achieve different decimal places by handling the CellEditorInitialized event and setting the DecimalPlaces property to the currently activated editor:
    Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles RadGridView1.CellEditorInitialized
        Dim spinEditor As GridSpinEditor = TryCast(e.ActiveEditor, GridSpinEditor)
        If spinEditor IsNot Nothing Then
            spinEditor.DecimalPlaces = e.RowIndex
        End If

    End Sub
The attached gif file illustrates the achieved result.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

George
Top achievements
Rank 1
Iron
commented on 18 Aug 2021, 01:14 PM

Thank you for your answer.

 

In my case, my radgridview Column is not editable,So in the read-only mode same decimal places are shown

Dess | Tech Support Engineer, Principal
Telerik team
commented on 19 Aug 2021, 06:52 AM

Hi, George,

If you need to format the values displayed in the cells while they are not being in edit mode, it is suitable to use the CellFormatting event and specify the CellElement.Text property: 

    Dim parsedValue As Decimal
    Private Sub RadGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs)
        If e.CellElement.ColumnInfo.Name = "UnitPrice" AndAlso e.CellElement.Value IsNot Nothing Then
            parsedValue = Decimal.Parse(e.CellElement.Value)
            e.CellElement.Text = parsedValue.ToString("N" & e.RowIndex)
        End If
    End Sub

George
Top achievements
Rank 1
Iron
commented on 19 Aug 2021, 07:03 AM

Thank you for your valuable reply
Tags
GridView
Asked by
George
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or