.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How To Add Datacolumn To Datagrid Through Code

Posted By:satyapriyanayak       Posted Date: March 25, 2013    Points: 40    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

How To Add Datacolumn To Datagrid Through Code
 

Public Class Form1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim table1 As DataTable

        table1 = New DataTable("Employees")

        Dim row1 As DataRow

        Dim FirstName As DataColumn = New DataColumn("First Name")

 

        table1.Columns.Add(FirstName)

        Dim Lastname As DataColumn = New DataColumn("Last Name")

        table1.Columns.Add("Last Name")

        Dim Age As DataColumn = New DataColumn("Age")

        table1.Columns.Add("Age")

        Dim Salary As DataColumn = New DataColumn("Salary")

        table1.Columns.Add("Salary")

        Dim Marks As DataColumn = New DataColumn("Marks")

        table1.Columns.Add("Marks")

 

        row1 = table1.NewRow()

        row1("First Name") = "Amit"

        row1("Last Name") = "Sharma"

        row1("Age") = 30

        row1("Salary") = "20000"

        row1("Marks") = "70"

        table1.Rows.Add(row1)

 

        row1 = table1.NewRow()

        row1("First Name") = "Rahul"

        row1("Last Name") = "Dravid"

        row1("Age") = 31

        row1("Salary") = "300000"

        row1("Marks") = "80"

        table1.Rows.Add(row1)

 

        row1 = table1.NewRow()

        row1("First Name") = "Sachin"

        row1("Last Name") = "Tendulkar"

        row1("Age") = 32

        row1("Salary") = "10000000"

        row1("Marks") = "90"

        table1.Rows.Add(row1)

 

        Dim ds As DataSet

        ds = New DataSet

        ds.Tables.Add(table1)

        DataGrid1.SetDataBinding(ds, "Employees")

    End Sub

End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend