Click here to Skip to main content
13,146,934 members (80,440 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 11 Mar 2004

Working with an unbound datagrid

, 11 Mar 2004
Rate this:
Please Sign up or sign in to vote.
This article explains about how to manage the unbounded datagrid for storing and editing values.


This article explains about how to manage the unbounded datagrid for storing and editing values. In earlier versions of Visual Basic, We make use of MS Flex Grid to manipulate the spreadsheet type of data. In Vb.Net you can use the datagrid for the same purpose and can add columns and rows dynamically. Let us see this in the example given below

  • Open a VisualBasic Project
  • Drop a Datagrid in the design view
  • Drop a Button
  • Change the button name property to btnAdd and text property to Add
  • Now in the general declaration section of the class declare these variables


'This is the table which will hold our columns and rows

Dim Tbl As New DataTable()
'This is the column type which will be added to the Datatable
Dim Col1 As New DataColumn()
Dim Col2 As New DataColumn()
Dim Col3 As New DataColumn()

'In the general section declare a procedure to format the datatable
  Private Sub FormatGrid()

        'Define column 1
        'Specify the column data type  
        Col1.DataType = System.Type.GetType("System.Int32")
        'This name is to identify the column
        Col1.ColumnName = "No"
        'This will enable automatically increment the data 
        Col1.AutoIncrement = True
        'This value will be displayed in the header of the column
        Col1.Caption = "No"
        'This will make this column read only,Since it is autoincrement
        Col1.ReadOnly = true
        'Now add this column to the datatable
        'Repeat the same procedure         
        'Define Column 2
        Col2.DataType = System.Type.GetType("System.String")
        Col2.ColumnName = "Name"
        Col2.Caption = "Name"
        Col2.ReadOnly = False
        'Define Column 3
        Col3.DataType = System.Type.GetType("System.String")
        Col3.ColumnName = "Address"
        Col3.Caption = "Address"
        Col3.ReadOnly = False
       DataGrid1.DataSource = Tbl
    End Sub
'now call this procedure in the load event of the form

' To add rows dynamically in the click event of the button, 
' include the code in the click event of the btnAdd
       'Create a row type variable

        Dim r As DataRow

        'Add a new row
        r = Tbl.NewRow()
        'Specify the  col name to add value for the row
        r("Name") = "ManojRajan"
        r("Address") = "New Delhi"
        'Add the row to the tabledata


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
I'm ManojRajan, Working as a consultant architect in Tennessee. I have more than 8 years of experience in Microsoft Technologies.

You may also be interested in...

Comments and Discussions

Generalassign datagrid1 value to the another datagrid Pin
Giri K20-Nov-07 17:42
memberGiri K20-Nov-07 17:42 
Questionhow to save those values into a database Pin
rsendhu4-Jun-07 20:37
memberrsendhu4-Jun-07 20:37 
Generaledit selected dynaic column in datagrid Pin
nishantmp11-Nov-06 19:14
membernishantmp11-Nov-06 19:14 
GeneralBut ... they're right! Pin
Todd Beaulieu28-Oct-06 10:11
memberTodd Beaulieu28-Oct-06 10:11 
Generalaaaaaaaaah! Pin
xoxoxoxoxoxox16-Feb-06 8:18
memberxoxoxoxoxoxox16-Feb-06 8:18 
GeneralThe title of the article is not what the article describes Pin
Anonymous30-Apr-05 9:10
sussAnonymous30-Apr-05 9:10 
Generalcomment on Working with an unbound datagrid by Coder12124 Pin
Coder1212414-Mar-04 22:11
sussCoder1212414-Mar-04 22:11 
GeneralI love these geeks Pin
Peace2u2-Jul-04 2:23
sussPeace2u2-Jul-04 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 12 Mar 2004
Article Copyright 2004 by ManojRajan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid