Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a DataGridView control that has its own data source loaded at run time in Visual Basic 2005
DescriptionThis example shows how to make a DataGridView control that has its own data source loaded at run time in Visual Basic 2005.
KeywordsDataGridView, DataTable, VB 2005
CategoriesDatabase, Controls
 
When its form loads, the program sets the DataGridView's ColumnCount property to 3 and then sets the columns' names. It then uses the control's Rows.Add method to add objects to the control.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    DataGridView1.ColumnCount = 3
    DataGridView1.Columns(0).Name = "First Name"
    DataGridView1.Columns(1).Name = "Last Name"
    DataGridView1.Columns(2).Name = "Occupation"
    DataGridView1.Rows.Add(New Object() {"Rod", "Stephens", _
        "Nerd"})
    DataGridView1.Rows.Add(New Object() {"Sergio", _
        "Aragones", "Cartoonist"})
    DataGridView1.Rows.Add(New Object() {"Eoin", "Colfer", _
        "Author"})
    DataGridView1.Rows.Add(New Object() {"Terry", _
        "Pratchett", "?"})
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated