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

Retrieve color of parent row

3 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 08 Jul 2015, 04:39 PM

Hello ... I've scoured the forums for an answer to this seemingly simple request. I have a template setup and it's working great. What I want to do is to 'paint' the color of the bounding box, for the child rows, the same color as their 'parent' row. I know I need to use ViewCellFormatting to achieve the painting of the box but I can't figure out how to get the row color (I'm using Conditional Formatting to color the parent rows) from the parent during the ViewCellFormatting event. The CellFormattingEventArgs only seems to expose the HierarchicalRowInfo object which, if I'm correct in my understanding, represents the Logical tree and the color of the row is from the Visual tree so I need the actual RowElement object representing the parent row. Below is the code for painting my bounding box:

As you can see, I'm using VB.NET but I can always translate C#. I want to replace the Color.GreenYellow with something like e.CellElement.Parent.BackColor. The problem is that the parent is the ScrollableRowsContainer element, not the GridDetailViewRowElement that I'm trying to get. How the heck can I achieve this?

Thanks, Jim

If TypeOf e.CellElement Is GridDetailViewCellElement Then
    Dim row As GridRowElement = e.CellElement.Parent 'This line doesn't actually retrieve the BackColor of the Parent!!!!!!
    e.CellElement.DrawFill = True
    e.CellElement.BackColor = Color.GreenYellow
    e.CellElement.Padding = New Padding(9, 4, 3, 4)
    e.CellElement.Margin = New Padding(10, 0, 0, 0)
    e.CellElement.Parent.
End If

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 09 Jul 2015, 03:03 PM
Hello Jim,

Thank you for writing.

Here is how you can access the parent row, row element and get its color:
Protected Overrides Sub OnLoad(e As EventArgs)
    MyBase.OnLoad(e)
 
    AddGridBoundToDataTablesWithHierarchy()
    AddHandler radGridView1.ViewCellFormatting, AddressOf radGridView1_ViewCellFormatting
 
    Dim obj As New ConditionalFormattingObject("ID", ConditionTypes.Greater, "5", "", True)
    obj.RowBackColor = Color.Red
    Me.radGridView1.Columns("ID").ConditionalFormattingObjectList.Add(obj)
End Sub
 
Private Sub radGridView1_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs)
    If TypeOf e.CellElement Is GridDetailViewCellElement Then
        Dim detailCell As GridDetailViewCellElement = DirectCast(e.CellElement, GridDetailViewCellElement)
        Dim parentRowElement As GridRowElement = radGridView1.TableElement.GetRowElement(TryCast(e.Row, GridViewDetailsRowInfo).Owner)
        If parentRowElement IsNot Nothing AndAlso parentRowElement.GetPropertyValue(LightVisualElement.BackColorProperty).ValueSource <> ValueSource.Style Then
            detailCell.BackColor = parentRowElement.BackColor
            detailCell.GradientStyle = GradientStyles.Solid
        Else
            detailCell.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
            detailCell.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
        End If
    End If
End Sub

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jim
Top achievements
Rank 1
answered on 09 Jul 2015, 04:26 PM
Stefan, thanks so much as that gave me what I was looking for. The key was the TableElement property of the GridView (which gave me the GridTableElement) and then the GridTableView's GetRowElement method to get the RowElement from the RowInfo. I'm slowly understanding things but it's tough to find some things in your documentation. I understand that part of that is because your tools are so extensive, it's just difficult to find things at times ... Thanks again!
0
Stefan
Telerik team
answered on 10 Jul 2015, 02:26 PM
No problem Jim, I am glad I could help. In general playing with the visual elements is not recommended as it might cause issues, hence these methods are not exposed in the documentation, but the below usage should be OK.

Should you have any other questions or suggestions, do not hesitate to contact us.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Jim
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jim
Top achievements
Rank 1
Share this question
or