Question Adding Property to DataGridView Column


New member
Dec 8, 2009
Programming Experience
Hello to everyone,
i have created one instance of datagridview on my form(by using the designer), with some

columns from a custom class (CustomDataGridViewTextBoxColumn) which inherits from the base DataGridViewTextBoxColumn class.

So far i ve added one extra property on my CustomDataGridViewTextBoxColumn.
It works ok so far and i can set my etxra property from within the designer.

The problem is that i cannot reference to this property from within my form by using datagridview1.columns("Test").CustomProperty.

This is a part of code that the designer has generated or forms load event


Me.DataGridView1 = New System.Windows.Forms.DataGridView
Me.Column1 = New WindowsApplication1.CustomDataGridViewTextBoxColumn

Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Column1})

Me.Column1.HeaderText = "Column1"
Me.Column1.myProperty = "1"
Me.Column1.Name = "Column1"

CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()


I can access my property by typing me.myproperty, but by using

Me.DataGridView1.Columns("test").myproperty i get error.

Well, i guess what when adding the custom columns to the datagrid, whose columns are converted to type DataGridViewColumn(which doesnt have my property).
Is it possible to add this property to the DataGridViewColumn class because its something i want to to for all the columns.

Thanks in advance!

below is my code

Option Explicit On
Imports System.ComponentModel

Public Class CustomDataGridViewTextBoxColumn
Inherits System.Windows.Forms.DataGridViewTextBoxColumn

Private mProperty As String

Public Property myProperty() As String
Return mProperty
End Get
Set(ByVal value As String)
mProperty = value
End Set
End Property

Public Overrides Function Clone() As Object
Dim Column As CustomDataGridViewTextBoxColumn = CType(MyBase.Clone(),

Column.myProperty = mProperty
Return Column
End Function

Public Sub New()
End Sub

End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
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)
If disposing AndAlso components IsNot Nothing Then
End If
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.DataGridView1 = New System.Windows.Forms.DataGridView
Me.Column1 = New WindowsApplication1.CustomDataGridViewTextBoxColumn
CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.DataGridView1.ColumnHeadersHeightSizeMode =

Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn()

Me.DataGridView1.Location = New System.Drawing.Point(25, 58)
Me.DataGridView1.Name = "DataGridView1"
Me.DataGridView1.Size = New System.Drawing.Size(378, 89)
Me.DataGridView1.TabIndex = 0
Me.Column1.HeaderText = "Column1"
Me.Column1.myProperty = "1"
Me.Column1.Name = "Column1"
Me.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.[True]
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(450, 293)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()

End Sub
Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
Friend WithEvents Column1 As WindowsApplication1.CustomDataGridViewTextBoxColumn
End Class
Top Bottom