Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / Windows Forms

DataGridView Custom Headers in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.56/5 (16 votes)
9 Mar 2009CPOL3 min read 185.6K   8.7K   47  
How to give Custom Headers to your DataGridView
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmMain
	Inherits System.Windows.Forms.Form

	'Form overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
		Try
			If disposing AndAlso components IsNot Nothing Then
				components.Dispose()
			End If
		Finally
			MyBase.Dispose(disposing)
		End Try
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _
	Private Sub InitializeComponent()
		Me.dgvData = New System.Windows.Forms.DataGridView
		Me.Column1 = New System.Windows.Forms.DataGridViewTextBoxColumn
		Me.Column2 = New System.Windows.Forms.DataGridViewTextBoxColumn
		Me.Column3 = New System.Windows.Forms.DataGridViewTextBoxColumn
		Me.Column4 = New System.Windows.Forms.DataGridViewTextBoxColumn
		Me.Column5 = New System.Windows.Forms.DataGridViewTextBoxColumn
		CType(Me.dgvData, System.ComponentModel.ISupportInitialize).BeginInit()
		Me.SuspendLayout()
		'
		'dgvData
		'
		Me.dgvData.BackgroundColor = System.Drawing.Color.White
		Me.dgvData.ColumnHeadersHeight = 25
		Me.dgvData.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Column1, Me.Column2, Me.Column3, Me.Column4, Me.Column5})
		Me.dgvData.Location = New System.Drawing.Point(0, 0)
		Me.dgvData.Name = "dgvData"
		Me.dgvData.RowHeadersVisible = False
		Me.dgvData.Size = New System.Drawing.Size(552, 303)
		Me.dgvData.TabIndex = 0
		'
		'Column1
		'
		Me.Column1.HeaderText = "Column1"
		Me.Column1.Name = "Column1"
		'
		'Column2
		'
		Me.Column2.HeaderText = "Column2"
		Me.Column2.Name = "Column2"
		'
		'Column3
		'
		Me.Column3.HeaderText = "Column3"
		Me.Column3.Name = "Column3"
		'
		'Column4
		'
		Me.Column4.HeaderText = "Column4"
		Me.Column4.Name = "Column4"
		'
		'Column5
		'
		Me.Column5.HeaderText = "Column5"
		Me.Column5.Name = "Column5"
		'
		'frmMain
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(587, 303)
		Me.Controls.Add(Me.dgvData)
		Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Margin = New System.Windows.Forms.Padding(4)
		Me.Name = "frmMain"
		Me.Text = "Form1"
		CType(Me.dgvData, System.ComponentModel.ISupportInitialize).EndInit()
		Me.ResumeLayout(False)

	End Sub
	Friend WithEvents dgvData As System.Windows.Forms.DataGridView
	Friend WithEvents Column1 As System.Windows.Forms.DataGridViewTextBoxColumn
	Friend WithEvents Column2 As System.Windows.Forms.DataGridViewTextBoxColumn
	Friend WithEvents Column3 As System.Windows.Forms.DataGridViewTextBoxColumn
	Friend WithEvents Column4 As System.Windows.Forms.DataGridViewTextBoxColumn
	Friend WithEvents Column5 As System.Windows.Forms.DataGridViewTextBoxColumn
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions