TelerikDeveloper.com

TelerikDeveloper.com

Joel 4/3/2012 8:09:07 PM

Telerik - Manually building a hierarchal grid

This code example shows how to build a Telerik hierarchal grid programmatically

 We make use of the TelerikGrid class located here:
http://dyndeveloper.com/thread.aspx?Threadid=1386

 

 



    Sub CreateGrid()
        Try
            '
            ' setup the main grid
            '
            'we make use of the TelerikGrid class located here 
            Dim oTelerikGrid As New TelerikGrid
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Price Level""prclevel", 11, 70))
            Dim oDT As DataTable = dynData.SPs.FP_IV00101_SEL4(appUser.Db).getTable
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.CreateGridViewComboBoxColumn("Item Number", oDT, "itemnmbr""itemnmbr""itemnmbr", 300))
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("UofM""UofM", 11, 70))
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.createGridViewDecimalColumn("Price""uomprice""{0:N2}", 80))
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.createGridViewCheckBoxColumn("Delete""Delete"))
            Me.RadGridView1.MasterTemplate.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("RowID""dex_row_id", 11, 70))
 
            'grid properties
            Me.RadGridView1.EnableGrouping = False
            Me.RadGridView1.AllowAddNewRow = True
            Me.RadGridView1.AllowDeleteRow = False
            Me.RadGridView1.AllowEditRow = True
            Me.RadGridView1.EnableFiltering = True
 
            'set the data source
            Me.RadGridView1.DataSource = dynData.SPs.FP_IVQuotedPriceLevels(appUser.Db).getTable
 
            '
            ' setup the child grid
            '
            Dim template As New GridViewTemplate()
            template.Columns.Add(oTelerikGrid.CreateGridViewComboBoxColumn("Item Number", oDT, "itemnmbr""itemnmbr""itemnmbr", 300))
            template.Columns(0).IsVisible = False
            template.Columns.Add(oTelerikGrid.createGridViewDecimalColumn("Price""unitprce""{0:N2}", 80))
            template.Columns.Add(oTelerikGrid.createGridViewDateTimeColumn("Effective""Effective"))
 
            'grid properties
            template.AllowAddNewRow = True
 
            'set the datasourse
            template.DataSource = SPs.FP_IV00108PriceHist_SEL(appUser.Db).getTable
 
            'add the child grid to the master
            RadGridView1.MasterTemplate.Templates.Add(template)
 
            'define the relationshop
            Dim relation As New GridViewRelation(RadGridView1.MasterTemplate)
            relation.ChildTemplate = template
            relation.RelationName = "Items"
            relation.ParentColumnNames.Add("itemnmbr")
            relation.ChildColumnNames.Add("itemnmbr")
            RadGridView1.Relations.Add(relation)
 
        Catch ex As Exception
            Throw ex
        End Try
 
    End Sub