Form with a grid and Export button

This SQL code will produce a code for a .NET form that has a Telerik RadGridView and an export button. 

You'll need to run all these functions first. 

 

I realized that not many people are going to want to create a form exactly the way that I create a form. It's pretty specific. But what you can get out of this is how to code T SQL code that creates code for a .NET form

 

Imports Telerik.WinControls
Imports Telerik.WinControls.UI
Imports Telerik.WinControls.UI.Export
Imports Telerik.WinControls.Export
Public Class COA
    Private Sub COA_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        Dispose()
        GC.Collect()
    End Sub
  
    Private Sub COA_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
  
            SetupGrid()
            BindGrid()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
  
    Private Sub SetupGrid()
        Try
            Dim oTelerikGrid As New FPTelerikCommon.TelerikGrid
            RadGridView1.Columns.Add(oTelerikGrid.createGridViewDecimalColumn("RowID", "RowID", "{0:f0}",80, False, False))
            RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("GL Account", "GL_Account", 100, 100, False, True))
            RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("GL Account Description", "GL_Account_Description", 255, 255, False, True))
            RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Reporting Group L2", "Reporting_Group_L2", 255, 255, False, True))
 
  
  
            'set grid level properties
            RadGridView1.EnableGrouping = False
            Me.RadGridView1.MasterTemplate.AutoExpandGroups = True
            RadGridView1.AllowAddNewRow = True
            RadGridView1.AllowDeleteRow = True
            RadGridView1.AllowEditRow = True
            RadGridView1.EnableFiltering = True
            RadGridView1.MasterTemplate.EnableSorting = True
  
  
        Catch ex As Exception
            MsgBox(ex.Message
        End Try
    End Sub
  
    Private Sub BindGrid()
        Try
            RadGridView1.DataSource = DAL.SPs.dd_COA_SEL("datawh").getTable
            RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
            For Each col As GridViewColumn In RadGridView1.Columns
                col.BestFit()
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
  
    Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
        Try
            FPTelerikCommon.TelerikGrid.ExportToXLSX(RadGridView1)
            MsgBox("Complete")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
  
    End Sub
End Class

 

 

declare @table varchar(100) = 'COA'
declare @grid varchar(max) = ''
 
SELECT @grid +=
    case data_type
        when 'varchar' then dbo.ddf_TelerikTextBoxColumn(Column_name, character_maximum_length, md.IsIdentity)
        when 'nvarchar' then dbo.ddf_TelerikTextBoxColumn(Column_name, character_maximum_length, md.IsIdentity)
        when 'int' then dbo.ddf_TelerikDecimalColumn(Column_name,  md.IsIdentity, md.NUMERIC_SCALE)
        when 'numeric' then dbo.ddf_TelerikDecimalColumn(Column_name,  md.IsIdentity, md.NUMERIC_SCALE)
        when 'float' then dbo.ddf_TelerikDecimalColumn(Column_name,  md.IsIdentity,2)
        when 'date' then dbo.ddf_TelerikDateColumn(Column_name)
        when 'datetime' then dbo.ddf_TelerikDateColumn(Column_name)
        else data_type
                end + char(10)
    from ddv_DALTableColumnMetaData md
    where TABLE_NAME = @table
 
 
print 'Imports Telerik.WinControls '
print 'Imports Telerik.WinControls.UI '
print 'Imports Telerik.WinControls.UI.Export '
print 'Imports Telerik.WinControls.Export '
print 'Public Class ' + @table + ' '
print '    Private Sub ' + @table + '_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed '
print '        Dispose() '
print '        GC.Collect() '
print '    End Sub '
print ' '
print '    Private Sub ' + @table + '_Load(sender As Object, e As EventArgs) Handles Me.Load '
print '        Try '
print ' '
print '            SetupGrid() '
print '            BindGrid() '
print '        Catch ex As Exception '
print '            MsgBox(ex.Message) '
print '        End Try '
print '    End Sub '
print ' '
print '    Private Sub SetupGrid() '
print '        Try'
print '            Dim oTelerikGrid As New FPTelerikCommon.TelerikGrid'
print left(@grid,8000)
print substring(@grid,8001,16000)
print ' '
print '            ''set grid level properties '
print '            RadGridView1.EnableGrouping = False '
print '            Me.RadGridView1.MasterTemplate.AutoExpandGroups = True '
print '            RadGridView1.AllowAddNewRow = True '
print '            RadGridView1.AllowDeleteRow = True '
print '            RadGridView1.AllowEditRow = True '
print '            RadGridView1.EnableFiltering = True '
print '            RadGridView1.MasterTemplate.EnableSorting = True '
print ' '
print ' '
print '        Catch ex As Exception '
print '            MsgBox(ex.Message'
print '        End Try'
print '    End Sub'
print ''
print '    Private Sub BindGrid()'
print '        Try'
print '            RadGridView1.DataSource = DAL.SPs.dd_' + @table + '_SEL("datawh").getTable'
print '            RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None'
print '            For Each col As GridViewColumn In RadGridView1.Columns'
print '                col.BestFit()'
print '            Next'
 
print '        Catch ex As Exception'
print '            MsgBox(ex.Message)'
print '        End Try'
print '    End Sub'
print ''
print '    Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click'
print '        Try'
print '            FPTelerikCommon.TelerikGrid.ExportToXLSX(RadGridView1)'
print '            MsgBox("Complete")'
print '        Catch ex As Exception'
print '            MsgBox(ex.Message)'
print '        End Try'
print ''
print '    End Sub'
print 'End Class'

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences