format cell in PivotGrid

1 Answer 94 Views
PivotGrid and PivotFieldList
Kobus
Top achievements
Rank 1
Iron
Kobus asked on 30 Sep 2022, 01:36 PM

Hello

 

I want to format the thousand separators in a PIVOTVIEW

My Code :

                e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                e.CellElement.ForeColor = Color.LightGreen;
                e.CellElement.Alignment = ContentAlignment.MiddleRight;
                //e.CellElement.Text = String.Format("{0:N3}");

the ForeColor is working,

but aligment right does not work ( see screen below)

and string format gives error

1 Answer, 1 is accepted

Sort by
0
Maria
Telerik team
answered on 04 Oct 2022, 01:32 PM

Hi Kobus,

Thank you for the image.

To format the separators in the RadPivotGrid you have to subscribe to the CellFormatting event , which fires when the cell element is updated and allows you to customize its appearance. In addition for the alignment, you need to use the TextAlignement property of the CellElement and for the GradientStyle, you have to set two other properties - DrawFill and BackColor.

this.radPivotGrid1.CellFormatting += RadPivotGrid1_CellFormatting;
private void RadPivotGrid1_CellFormatting(object sender, PivotCellEventArgs e)
{
    e.CellElement.TextAlignment = ContentAlignment.MiddleRight;
    e.CellElement.DrawFill = true;
    e.CellElement.BackColor = Color.Black;
    e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
    e.CellElement.ForeColor = Color.LightGreen;
}

I am sending you a link to the documentation as well: Properties, Methods, Events

For the String.Format error you have to change your code like this because the provided code snippet doesn't seem to be valid, I am giving you an example:

decimal number = 123;
string element = e.CellElement.Text = String.Format("{0:N3}", number);
In your case, the number variable from the example has to be the element from the cell that you take from the DataSource bound to the RadPivotGrid.

 

Regards,
Maria
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
PivotGrid and PivotFieldList
Asked by
Kobus
Top achievements
Rank 1
Iron
Answers by
Maria
Telerik team
Share this question
or