This is a migrated thread and some comments may be shown as answers.

RadGridView_CellFormatting No Effect

3 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jean-Charles
Top achievements
Rank 1
Jean-Charles asked on 01 Jan 2020, 09:32 AM

Hi,

I've a problem with my CellFormating.
More precisely with "FormatString" which does not work properly.

I filled my RadGridView with the help of a list.
Everything is working properly.
Here is a bit of my implementation:

Public Class Liste_DossiersVO
 
   '...
   Private dvo_prix_public As String
   '...
 
   Public Property Prix_Public() As String
       Get
           Return dvo_prix_public
       End Get
       Set(value As String)
           dvo_prix_public = value
       End Set
   End Property
 
   Public Sub New(...,
                  Prix_Public As String,
                  ...)
       Me.Prix_Public = Prix_Public
   End Sub
 
   Default Public ReadOnly Property Item(ByVal i As Integer) As Object
       Get
           Select Case i
               ...
               Case 6
               ...
               Case Else
                   Return [String].Empty
           End Select
       End Get
   End Property
    
End Class
 
 
 
 
 
Public Sub Binding_Liste_DossiersVO()
       Using db As New NpgsqlConnection
               Dim sql As NpgsqlCommand = db.CreateCommand()
               Try
                   db.ConnectionString = ParamSQL
                   db.Open()
 
                   If db.State = ConnectionState.Open Then
 
                       sql.Parameters.Clear()
                       sql.CommandType = CommandType.Text
 
                       sql.CommandText = "SELECT ...
                                     FROM "...;"
 
                       Dim reader As IDataReader = sql.ExecuteReader()
                       Data_GridView_VO.Clear()
                       While reader.Read()
 
                       Dim LVO As New Liste_DossiersVO(Convert.ToString(reader(0)),
                                                           Convert.ToString(reader(1)), 
                                                           Convert.ToString(reader(2)), 
                                                           Convert.ToString(reader(3)), 
                                                           Convert.ToString(reader(4)), 
                                                           Convert.ToString(reader(5)), 
                                                           Convert.ToString(reader(6)),  'dvo_prix_public --> Prix_Public
                                                           Convert.ToString(reader(7))) 
 
                       Data_RadGridView1.Add(LVO)
 
                       End While
                   End If
               db.Close()
               Catch ex As Exception
                   db.Close()
                   ErrorBox.RadTextBoxControl1.Text = ex.ToString
                   ErrorBox.Show()
               End Try
       End Using
   End Sub
    
    
    
   Public Sub BindToRadGridView1()
       Home.GridView_VO.MasterTemplate.AllowAddNewRow = False
       Home.GridView_VO.MasterTemplate.AutoGenerateColumns = False
       Home.GridView_VO.DataSource = Nothing
       Home.GridView_VO.TableElement.BeginUpdate()
       Home.GridView_VO.MasterTemplate.Columns.Clear()
       '...
       Home.GridView_VO.MasterTemplate.Columns.Add(New GridViewDecimalColumn("PRIX PUBLIC", "Prix_Public"))
 
       For i As Integer = 0 To Home.GridView_VO.MasterTemplate.Columns.Count - 1
           Home.GridView_VO.MasterTemplate.Columns(i).Width = 150
       Next i
 
       Home.GridView_VO.TableElement.EndUpdate(False)
       Home.GridView_VO.DataSource = Data_GridView_VO
   End Sub

 

Then when I try to format the display of my 6th column with my currency format it doesn't work.
The rest works well.
For example, a color change works without problems.
Also, if I add € to "{0: C}" -> "{0: C} €" the currency sign looks good but the formatting is not the right one -> € 1,250.00
The correct form should be € 1,250.00

I tried several implementation attempts but never got the right result :

 

Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    If e.CellElement.ColumnInfo.Name = "PRIX PUBLIC" Then
        If e.CellElement.Text <> "" Then
            e.CellElement.Text = String.Format(New CultureInfo("fr-FR"), "{0:C}", e.CellElement.Value)
        End If
    End If
End Sub

Or simple

Me.RadGridView1.Columns(6).FormatInfo = CultureInfo.CreateSpecificCulture("fr-FR")
Me.RadGridView1.Columns(6).FormatString = "{0:C}"

 

Doesn't work.

 

Do you have any idea?

A solution ?
Thank you.

 

3 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 02 Jan 2020, 03:39 PM

Hello Jean-Charles,

It seems that you have a column with numeric values in your RadGridView and you would like to show currency format. In this case, I can suggest you to use a GridViewDecimalColumn that allows decimal data to be displayed. You can set its FormatString property to a specified numeric type that satisfies your custom requirement. After some research in general programming forums, I found out that setting the FormatInfo property to "en-FR" will display the currency in € in front of the numeric value with a comma for thousands separator and a dot for the coins:
https://stackoverflow.com/questions/47612295/how-to-display-the-euro-symbol-at-the-front-of-the-number-when-using-cultureinfo

Please refer to the following code snippet which result is demonstrated below:

GridViewDecimalColumn decimalCol = radGridView2.Columns["DecimalColumn"] as GridViewDecimalColumn;

if (decimalCol != null)
{
    decimalCol.FormatInfo = CultureInfo.CreateSpecificCulture("en-FR");
    decimalCol.FormatString = "{0:C}";
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jean-Charles
Top achievements
Rank 1
answered on 02 Jan 2020, 07:04 PM

Hello Nadya,

 

I already use a GridViewDecimalColumn

Public Sub BindToGridView_VO()
        Home.GridView_VO.MasterTemplate.AllowAddNewRow = False
        Home.GridView_VO.MasterTemplate.AutoGenerateColumns = False
        Home.GridView_VO.DataSource = Nothing
        Home.GridView_VO.TableElement.BeginUpdate()
        Home.GridView_VO.MasterTemplate.Columns.Clear()
        '...
        Home.GridView_VO.MasterTemplate.Columns.Add(New GridViewDecimalColumn("PRIX PUBLIC", "Prix_Public"))
 
        Home.GridView_VO.TableElement.EndUpdate(False)
        Home.GridView_VO.DataSource = Data_GridView_VO

 

Your code has no effect, and neither does it:

Private Sub GridView_VO_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles GridView_VO.CellFormatting
        If e.CellElement.ColumnInfo.Name = "PRIX PUBLIC" Then
            If e.CellElement.Text <> "" Then
                e.CellElement.Text = String.Format(New CultureInfo("fr-FR"), "{0:C}", e.CellElement.Value)
            End If
        End If  
End Sub

 

 

 

 

 

 


0
Nadya | Tech Support Engineer
Telerik team
answered on 07 Jan 2020, 01:58 PM

Hello Jean-Charles,

According to the provided code snippet, I can not see whether you set the FormatInfo and FormatString properties to the decimal column. I have attached my test project to this thread as well. Could you please give it a try and let me know how it works for you? If you are experiencing further difficulties I would kindly ask you to modify the attached project and get it back to me so we can investigate the precise case.

I am looking forward to your reply.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Jean-Charles
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Jean-Charles
Top achievements
Rank 1
Share this question
or