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

PropertyGrid: Apply format decimals e.g. "125.00"

2 Answers 148 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Eusebio
Top achievements
Rank 1
Veteran
Eusebio asked on 02 Dec 2020, 03:11 PM

How can I format fields of my Decimal type class?

125 ---> 125.00
80.0000 -> 80.00

See image and class.

Also, how can I change the font size of only some fields?

 

Thanks,

 

Best regards

 

2 Answers, 1 is accepted

Sort by
0
Eusebio
Top achievements
Rank 1
Veteran
answered on 02 Dec 2020, 03:13 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace DAL.ENTITY
{
    public class DAL_ViewHc
    {

        // ** NO es un POCO **
        // Clase que representa la vista de las propiedades de la Hoja de calculo
        // Inicialmente hecho para el RPG de Propiedades de la parte de
        // arriba de la Hoja de calculo.

        private Guid guid;                // CAMPOS ocultos DEL PROPERTY GRID


        // Grupo: Total.------------------------------------------------
        //private decimal tiempo_ciclo;
        private decimal? tiempo_ciclo;
        private decimal actividad;

        private decimal? ciclosHora; // calculados
        private decimal? prodHora; // calculados
        private decimal? tiempoPieza; // mismo que el tiempo_ciclo

        private decimal? actividadPromedio;
        private decimal? hhc;

        // Grupo: Tiempos.------------------------------------------------
        private decimal? tiempoBasico;
        private decimal suplementoFrecuencia;


        // Grupo: Suplementos por descanso.------------------------------------------------
        private decimal necesidadesPersonales;
        private decimal fatiga;


        // Grupo: Operaciones de calculo------------------------------------------------
        private string sistema;
        private Int16 unidadesCiclo;
        private byte numOperarios;  // HC.NUMOPERARIOS.  -- sql=tinyInt



        //***********************************************************************
        // PROPIEDADES :
        //***********************************************************************

        [Browsable(false)]
        public Guid Guid { get => guid; set => guid = value; }


        // Grupo: Total.------------------------------------------------
        [Browsable(false)]  // No se mostraran en el RPG
        //public decimal Tiempo_ciclo { get => tiempo_ciclo; set => tiempo_ciclo = value; }
        public decimal? Tiempo_ciclo { get => tiempo_ciclo; set => tiempo_ciclo = value; }
        [Browsable(false)]
        public decimal Actividad { get => actividad; set => actividad = value; }

        [Category("Total")]
        [ReadOnly(true)]
        [DisplayName("Ciclos/hora")]
        public decimal? CiclosHora { get => ciclosHora; set => ciclosHora = value; }

        [Category("Total")]
        [ReadOnly(true)]
        [DisplayName("Prod/Hora")]
        public decimal? ProdHora { get => prodHora; set => prodHora = value; }


        [Category("Total")]
        [ReadOnly(true)]
        [DisplayName("Tiempo pieza")]

        public decimal? TiempoPieza { get => tiempoPieza; set => tiempoPieza = value; }



        [Category("Total")]
        [ReadOnly(true)]
        [DisplayName("Actividad promedio")]

        public decimal? ActividadPromedio { get => actividadPromedio; set => actividadPromedio = value; }

        [Category("Total")]
        [ReadOnly(true)]
        [DisplayName("HhC")]
        public decimal? Hhc { get => hhc; set => hhc = value; }


        // Grupo: Tiempos------------------------------------------------
        // amq aki

        [Category("Tiempos")]
        [ReadOnly(true)]
        [DisplayName("Tiempo básico")]
        public decimal? TiempoBasico { get => tiempoBasico; set => tiempoBasico = value; }


        [Category("Tiempos")]
        [ReadOnly(true)]
        [DisplayName("Suplemento frecuencia")]
        public decimal SuplementoFrecuencia { get => suplementoFrecuencia; set => suplementoFrecuencia = value; }



        // Grupo: Suplementos por descanso.------------------------------------------------

        //private decimal necesidadesPersonales;
        //private decimal fatiga;

        [Category("Suplementos por descanso")]
        [ReadOnly(true)]
        [DisplayName("Necesidades personales")]

        public decimal NecesidadesPersonales { get => necesidadesPersonales; set => necesidadesPersonales = value; }

        [Category("Suplementos por descanso")]
        [ReadOnly(true)]
        [DisplayName("Fatiga")]

        public decimal Fatiga { get => fatiga; set => fatiga = value; }


        // Grupo: Operaciones de calculo------------------------------------------------
        [Category("Operaciones de cálculo")]
        [ReadOnly(true)]
        [DisplayName("Sistema")]

        public string Sistema { get => sistema; set => sistema = value; }

        [Category("Operaciones de cálculo")]
        [ReadOnly(true)]
        [DisplayName("Unidades/Ciclo")]

        public short UnidadesCiclo { get => unidadesCiclo; set => unidadesCiclo = value; }

        [Category("Operaciones de cálculo")]
        //[ReadOnly(true)]
        [DisplayName("Operarios")]

        public byte NumOperarios { get => numOperarios; set => numOperarios = value; }





        // Estudios
        // TIEMPO_CICLOnumeric(12, 4)

        // HC:
        // ActividadsmallmoneyValor fijo 100




    }
}

0
Nadya | Tech Support Engineer
Telerik team
answered on 03 Dec 2020, 02:30 PM

Hello, Eusebio,

You can use the following approach to apply a custom format to decimal values and also change the font for specific fields:

 public RadForm1()
 {
     InitializeComponent();

     radPropertyGrid1.SelectedObject = new DoubleItem(125);

     radPropertyGrid1.EditorInitialized += radPropertyGrid1_EditorInitialized;
     radPropertyGrid1.ItemFormatting += this.RadPropertyGrid1_ItemFormatting;
 }

 Font f = new Font("Times New Roman", 12, FontStyle.Bold);
 private void RadPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
 {
     if (e.Item.Name == "DecimalValue")
     {
         ((PropertyGridItemElement)e.VisualElement).ValueElement.Text = string.Format("{0:N2}", ((PropertyGridItem)e.Item).Value);
         ((PropertyGridItemElement)e.VisualElement).ValueElement.Font = f;
     }
 }

 private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
 {
     PropertyGridSpinEditor editor = e.Editor as PropertyGridSpinEditor;
     if (editor != null)
     {
         ((BaseSpinEditorElement)editor.EditorElement).DecimalPlaces = 2;

     }
 }

 public class DoubleItem
 {
     public double DecimalValue { get; set; }

     public DoubleItem(double decimalValue)
     {
         this.DecimalValue = decimalValue;
     }
 }

I hope this helps. Please let me know if you have other questions.

Regards,
Nadya
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/.

Tags
PropertyGrid
Asked by
Eusebio
Top achievements
Rank 1
Veteran
Answers by
Eusebio
Top achievements
Rank 1
Veteran
Nadya | Tech Support Engineer
Telerik team
Share this question
or