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
 
 
 
 
 
TitleDisplay a caption for a DataTable in a DataGrid in Visual Basic .NET
DescriptionThis example shows how to display a caption for a DataTable in a DataGrid in Visual Basic .NET.
KeywordsDataTable, caption, DataGrid, VB.NET
CategoriesVB.NET, Controls, Database
 
The following code makes a DataTable, defines its columns, and then adds data to it. It attaches the DataTable to a DataGrid and defines a caption for the grid.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Make the DataTable and give it columns.
    Dim dt As New DataTable("Purchases")
    dt.Columns.Add("Selected", GetType(Boolean))
    dt.Columns.Add("Item", GetType(String))
    dt.Columns.Add("Quantity", GetType(Integer))
    dt.Columns.Add("Price", GetType(Single))

    ' Add data to the DataTable.
    dt.Rows.Add(New Object() {True, "Donut", 12, 2.37})
    dt.Rows.Add(New Object() {True, "CD-RW Disks", 20, _
        16.95})
    dt.Rows.Add(New Object() {False, "Laptop Computer", 1, _
        995.0})
    dt.Rows.Add(New Object() {True, "Cookie", 1440, 37.5})

    ' Attach the DataTable to the DataGrid.
    DataGrid1.DataSource = dt

    ' Set the table's caption.
    DataGrid1.CaptionText = "Purchases"
    DataGrid1.CaptionVisible = True
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated