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

Self-referencing hierarchy dynamicaly

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 25 Jan 2011, 08:14 PM
I am trying to look for an example in VB on how to create a Self-referencing hierarchy grid dynamicaly.  I have created one where i declare all the columns and parameters.  However I want to create it entirly dynamicaly.  I am already creating a standard grid in this manner, however I wish to add this option into the user control created.

I included some code, however would like to see an example if possible. 
' the nestedDatasource is a dataset with a relation added  
 
 
  If NestedTable Then
            RadGrid1.EnableLinqExpressions = False
            RadGrid1.ClientSettings.AllowExpandCollapse = True
            RadGrid1.MasterTableView.HierarchyDefaultExpanded = False
            RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind
            RadGrid1.MasterTableView.SelfHierarchySettings.KeyName = NestedTableKey
            RadGrid1.MasterTableView.SelfHierarchySettings.ParentKeyName = NestedTableParentKey
            ' RadGrid1.MasterTableView.SelfHierarchySettings.MaximumDepth = 0
 
            Dim expandCollapseColumn As New GridExpandColumn
            expandCollapseColumn.HeaderStyle.Width = 20
            RadGrid1.MasterTableView.Columns.Add(expandCollapseColumn)
 
 
            RadGrid1.MasterTableView.ShowHeader = False
            RadGrid1.MasterTableView.HierarchyDefaultExpanded = False
 
 
            Datasource = NestedDatasource.Tables(0)
        End If
 
....
 
'create the columns dynamicaly from the dataset
                            boundColumn = New GridBoundColumn
                            RadGrid1.MasterTableView.Columns.Add(boundColumn)
                            boundColumn.DataField = column.ColumnName
                            boundColumn.HeaderText = column.ColumnName.Replace("_", " ").ToLower()
                        If colDataType = "int32" Then
                            boundColumn.DataFormatString = "<nobr>{0:N0}</nobr>"
                            boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
                        .....
.....
 
 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
 
        If NestedTable Then
            RadGrid1.MasterTableView.VirtualItemCount = NestedDatasource.Tables(0).Rows.Count()
            RadGrid1.DataSource = NestedDatasource
            RadGrid1.Visible = True
        Else
            If Not Datasource Is Nothing Then
                RadGrid1.MasterTableView.VirtualItemCount = Datasource.Rows.Count()
                RadGrid1.DataSource = Datasource
                RadGrid1.Visible = True
            Else
                RadGrid1.Visible = False
                Exit Sub
            End If
        End If
    End Sub
Just a snippet, the issue I have with this is that when I click on the arrow, nothing expands.  Not sure where I am going wrong here.  Like I said I can get it working when not creating it dynamicaly.  Also like to add, I am plugging this into a usercontrol that already creates a normal grid dynamicaly. 

Just wondering If I need to do something extra?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 31 Jan 2011, 04:51 PM
Hello Mabs,

I attached a runnable project that demonstrates how to create a self-referencing grid programmatically. The code is based on the Self-referencing Hierarchy demo.

Let me know whether this helps.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
mabs
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or