VB icon

DataGrid Columns

Email
Submitted on: 1/2/2015 12:22:00 AM
By: Johan Strydom (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: VB.NET
Views: 486
 
     The purpose of the code is to show how to add columns to a VB.NET DataGrid control.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: DataGrid Columns
// Description:The purpose of the code is to show how to add columns to a VB.NET DataGrid control.
// By: Johan Strydom (from psc cd)
//
// Inputs:NoN
//
// Returns:NoN
//
// Assumes:Add a datagrid control to your form. called DataGrid1 
Double click on your form and replace the Form1_Load() function with the code...
//
// Side Effects:NoN
//**************************************

'You can't have a data grid column without a DataTable ... I think :)
 Private dbTable As New DataTable("DTBL1")
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 Dim i = 0
 'Add 4 columns to the table
 For i = 1 To 4
dbTable.Columns.Add("Col" & i)
 Next
 'Set the datasource to our database table
 DataGrid1.DataSource = dbTable
 End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.