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

[Solved] 3 level hierarchy hiding +

2 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 22 Apr 2008, 10:17 PM
I need a little help here on identifying the correct level of hierarchy when running this code. I modified your code to hide the + sign for items that don't have sub-items. It's a little quicker than the one you guys document because it doesn't require you to set the auto-expand to true.

    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
        If Not Page.IsPostBack Then 
            For Each item As GridDataItem in RadGrid1.MasterTableView.Items 
                Dim task_id As String = (TryCast(item.FindControl("lbl_task_id"), Label)).Text 
                If task_id = "" Then 
                    Dim cell As TableCell = item.Item("ExpandColumn") 
                    Dim expandCollapseButton As ImageButton = CType(cell.Controls(0), ImageButton) 
                    expandCollapseButton.Visible = False 
                End If 
            Next 
        End If 
    End Sub 

The query for my master table brings back the max id value of the sub-items. If it brings back an empty value, I know there are no sub-items and the code hides the +.

So all of this is working great. I'm trying to use the same theory on another project that has a 3 level hierarchy. I don't need to worry about the master table view since I want that to always expand. But I only want the 2nd detail level to expand if I bring back a value in my query.

My question is how to setup the loop in the above code to look at the detail table items. As you can see, it looks at RadGrid1.MasterTableView.Items. Is there another property I can use to look at Detail TableView Items?

Any suggestions you may have are greatly appreciated. Thanks.

2 Answers, 1 is accepted

Sort by
0
Philip Senechal
Top achievements
Rank 1
answered on 22 Apr 2008, 11:54 PM
HOLY SCHNIKEY! I actually got it to work :)

I used the NestedView properties to get it to work...here's the code if anyone is interested:

Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
    Dim masterView As GridTableView = RadGrid1.MasterTableView 
    Dim nestedViewItems As GridItem() = masterView.GetItems(GridItemType.NestedView) 
    For Each nestedViewItem As GridNestedViewItem In nestedViewItems 
        For Each nestedView As GridTableView In nestedViewItem.NestedTableViews 
            If nestedView.Name = "detail" Then 
                For Each item As GridDataItem in nestedView.Items 
                    Dim adv_substep_id As String = (TryCast(item.FindControl("lbl_adv_substep_id"), Label)).Text 
                    If adv_substep_id = "" Then 
                        Dim cell As TableCell = item.Item("ExpandColumn") 
                        Dim expandCollapseColumn As Button = CType(cell.Controls(0), Button) 
                        expandCollapseColumn.Visible = False 
                    End If 
                Next 
            End If 
        Next 
    Next 
End Sub 

This is for 2008.1. If you're still using 2007.3, you have to cast the expandCollapseColumn as an ImageButton instead.

If you're wondering what adv_substep_id is, I just did a sub-query within the 1st detail table query that grabs the max id of any items that would be in the 2nd detail table for that record. It then populates that to a hidden column in the 1st detail table...that's how I can check the label for "". If any records exist in the 2nd detail table, that label will be the max ID, otherwise it's empty.
0
Sebastian
Telerik team
answered on 23 Apr 2008, 07:56 AM
Hello Philip,

Indeed if you want to reference the expand/collapse button you should case the first control in the corresponding cell to button since by default it is sprite button. See the documentation topic linked below for more info:

CSS sprites help article

The update version of the help article illustrating how to remove the expand/collapse images in hierarchy when there are no records to display can be found here.

Kind regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Philip Senechal
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or