Please see the attached image. Can someone explain to me how to have the forecolor of the text, currently shown in red, to only display as red if the Source <> Employee? In the image, only one employees hours / units should be displayed in red (the employee whose source = Third Party).
Apologies to admins for the double posting, but my deadline to complete this requirement is running out.
Can someone please offer some advice? Surely this scenario has come up before.
Thanks in advance.
8 Answers, 1 is accepted
Thank you for writing.
You can use the following approach for this:
private void RadPivotGrid1_CellFormatting(object sender, PivotCellEventArgs e){ if (e.CellElement.Row.Name == "October") { e.CellElement.ForeColor = Color.Red; } else { e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local); }}I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
Okay, so if Row.Name = Source...
Then how to I evaluate the data in the Source column (in this case, row?) to see if its equal to 'Third Party'?
Dess was able to provide me an example which I was able to modify to my own usage. For anyone who has the same issue, see sample code and image to see how to acheive the formatting.
' Display hours as red if employee is a non-company employee Dim groupNode As PivotGroupNode = TryCast(e.CellElement.Row, PivotGroupNode) Dim parentGroupNode As PivotGroupNode = TryCast(e.CellElement.Row.Parent, PivotGroupNode) If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Then e.CellElement.ForeColor = Color.Red ElseIf parentGroupNode IsNot Nothing AndAlso parentGroupNode.Name = "Third Party" Then e.CellElement.ForeColor = Color.Red Else e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local) End If
Thank Dess and Dimitar!
And I thought I was done, but...
How would I apply the same logic in PrintElementFormatting of a PivotGrid?
The approach is similar you just need to cast the PrintElement in order to access the Row property. For example:
Private Sub RadPivotGrid1_PrintElementFormatting(ByVal sender As Object, ByVal e As PrintElementEventArgs) Dim cell As PivotCellPrintElement = TryCast(e.PrintElement, PivotCellPrintElement) If cell IsNot Nothing AndAlso cell.Row.Name = "October" Then cell.BackColor = Color.Red End IfEnd SubPlease let me know if there is something else I can help you with.
Dimitar
Telerik by Progress
Getting closer, but that changes everything. Perhaps I am asking wrong...
Can you explain how I can implement the below code, which works for CellFormatting, to work for PrintElementFormatting ?
Dim groupNode As PivotGroupNode = TryCast(e.CellElement.Row, PivotGroupNode)Dim parentGroupNode As PivotGroupNode = TryCast(e.CellElement.Row.Parent, PivotGroupNode)If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Thene.CellElement.ForeColor = Color.RedElseIf parentGroupNode IsNot Nothing AndAlso parentGroupNode.Name <> "Employee" Thene.CellElement.ForeColor = Color.RedElsee.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)End IfEnd IfYou have to replace "e.CellElement" with the casted object "cell", no need to the reset the values. Here is the code:
Private Sub RadPivotGrid1_PrintElementFormatting(ByVal sender As Object, ByVal e As PrintElementEventArgs) Dim cell As PivotCellPrintElement = TryCast(e.PrintElement, PivotCellPrintElement) If cell IsNot Nothing Then Dim groupNode = TryCast(cell.Row, PivotGroupNode) Dim parentgroupNode = TryCast(cell.Row.Parent, PivotGroupNode) If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Then cell.ForeColor = Color.Red ElseIf parentgroupNode IsNot Nothing AndAlso parentgroupNode.Name <> "Employee" Then cell.ForeColor = Color.Red End If End IfEnd SubDo not hesitate to contact us if you have other questions.
Regards,
Dimitar
Telerik by Progress
