VB.NET - How To Bind DataGridView Using Datatable

VB.NET - How To Load Datatable Data To DataGridView Using VB.NET 


In This VB.NET Tutorial We Will See How To Populate a DataGridView From DataTable Using VB.NET Programming Language.

Project Source Code:

Imports System.Data.DataTable
Public Class Bind_DatagridView_Wth_DataTable

    ' Create a new datatable
    Dim table As New DataTable("Table")
    Private Sub Bind_DatagridView_Wth_DataTable_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' Add columns to your datatable, 
        ' with the name of the columns and their type 

        table.Columns.Add("Id", Type.GetType("System.Int32"))
        table.Columns.Add("First Name", Type.GetType("System.String"))
        table.Columns.Add("Last Name", Type.GetType("System.String"))
        table.Columns.Add("Age", Type.GetType("System.Int32"))

        ' Add rows to the datatable with some data

        table.Rows.Add(1, "XXXX", "YYYYY", 21)
        table.Rows.Add(2, "SSDD", "hGSQ", 33)
        table.Rows.Add(3, "fgfgd", "jgfdd", 53)
        table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 19)
        table.Rows.Add(5, "hghfd", "ghjgdf", 36)
        table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 63)

    ' now set the datagridview datasource equals to your datatable name

        DataGridView1.DataSource = table

    End Sub

End Class


VB.NET Fill DataGridView Using DataTable
VB.NET - Fill DataGridView Using DataTable

Share this

Related Posts

Next Post »