The following code (called from RadGrid_PreRender) will iterate through a radgrid (and 3 nested tables) and hide the expand button if the row has no child records. I pieced this together from samples on this forum.
1) The MasterTableView is first populated by a call to NeedDataSource
2) The rows for the related nested tables are called by the DetailTableDataBind method
3) HierarchyLoadMode="ServerOnDemand" for all 4 tables ("Client" is not acceptable due to number of records)
Now, the last 3 lines of code (below, currently commented out) will collapse the MasterTableView nicely. However, upon expanding a row from that MasterTableView, the nested tables within are all expanded - not collapsed - as I need them to be.
I have exhausted so many possibilities, so I finally posted this here. Note: This is not a question of how to hide the expand column (as is discussed in previous posts). Rather, it is a matter of making already collapsed tables STAY collapsed when the MasterTableView is expanded.
I suspect the problem lies within the DetailTableDataBind being called by ServerOnDemand after the MasterTableView row is clicked (thusly, repopulating the tables and overwriting any hiding/collapsing that has already been perfomed). Basically, I really need to know how to call "HideExpandColumnRecursive" on NESTED detail tables after they are created (which happens after a MasterTableView has been expanded). Complicated, I know. Any help would be greatly appreciated.
Protected
Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
HideExpandColumnRecursive(RadGrid1.MasterTableView)
End If
End Sub
Public
Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)
Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)
For Each nestedViewItem As GridNestedViewItem In nestedViewItems
For Each nestedView As GridTableView In nestedViewItem.NestedTableViews
If nestedView.Items.Count = 0 Then
Dim cell As TableCell = nestedView.ParentItem("ExpandColumn")
Dim expandCollapseButton As Button = CType(cell.Controls(0), Button)
expandCollapseButton.Visible =
False
nestedViewItem.Visible =
False
End If
If nestedView.HasDetailTables Then
HideExpandColumnRecursive(nestedView)
End If
Next
Next
'For Each item As GridDataItem In RadGrid1.MasterTableView.Items
' item.Expanded = False
'Next
End Sub