Even though I have my issues with Infragistics WebHierarchicalDataGrid control, it has some neat features and I found that with some tweaks you can make it work.
Case in point: Manual Load on Demand. If you have hierarchical data structure, it allows you to retrieve only root level data and then when user clicks “Expand” arrow – get additional data on as needed basis:
This is achieved by handling RowIslandsPopulating grid’s event in which you can run a DB query based on parent row data, then manually create a ContainerGrid object bind it to the data and add it to parent row RowIslands collection:
Protected Sub myGrid_RowIslandsPopulating(ByVal sender As Object, ByVal e As ContainerRowCancelEventArgs) Handles myGrid_.RowIslandsPopulating e.Cancel = True Dim oData as SomeDataType = GetData() Dim oChildGrid As New ContainerGrid() e.Row.RowIslands.Add(oChildGrid) oChildGrid.DataKeyFields = "SOME_ID" oChildGrid.Level = e.Row.Level + 1 oChildGrid.DataSource = oData oChildGrid.DataBind() End Sub
For this approach to work top-level rows need to display “Expand” arrows that user can click. This is done by looping thru all top-level rows in grid’s PreRender event, setting each row’s IsEmptyParent property to true:
Protected Sub myGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles myGrid.PreRender If myGrid.DataSource IsNot Nothing Then For Each oRow As ContainerGridRecord In myGrid.GridView.Rows Row.IsEmptyParent = True Next End If End Sub
This should work, but unfortunately if your source for the root level grid is DataSet – it doesn’t.
The reason – WebHierarchicalDataGrid expects hierarchy in the data source and if DataSet has a single table and no relationship – the “Expand” arrows will never be rendered. So we have to fake it (Great minds think alike, I found this solution in the same time it was suggested by Infragistics support). Once your root DataSet is filled with data, add following code:
oMyDataSet.Tables.Add() oMyDataSet.Tables(1).Columns.Add("MY_ID", GetType(Integer)) oMyDataSet.Relations.Add(oMyDataSet.Tables(0).Columns("MY_ID"), oMyDataSet.Tables(1).Columns("MY_ID"))
Just substituted “MY_ID” with some real column ID from your root table. The code will create fake relationship letting grid to render “Expand” arrows when running code from above in PreRender event.