I think you should overrided DataGridViewTextBoxColumn Like as bellow:
Public Class sampleDataGridViewNumberTextBoxColumn
Inherits System.Windows.Forms.DataGridViewTextBoxColumn
//Define in here
EndClass
Pls refer this
link[
^]
This is sample code to customize GridViewTextboxColumn to GridViewNumberTextboxColumn:
Option Explicit On
Option Strict On
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class sampleDataGridViewNumberTextBoxColumn
Inherits System.Windows.Forms.DataGridViewTextBoxColumn
Private _orijinalText As String
Private _minValue As Decimal
Private _maxValue As Decimal
Private _CellValueType As Type
Sub New()
InitializeComponent()
Me.DefaultCellStyle.Format = "#,##0"
Me._orijinalText = ""
Me._minValue = -999999999
Me._maxValue = 999999999
Me._CellValueType = Type.Number
SetMaxLength(Me.DefaultCellStyle.Format, _minValue, _maxValue)
Dim cell As New sampleDataGridViewDateTextBoxCell()
Me.CellTemplate = cell
End Sub
Public Overrides Function Clone() As Object
Dim cloneObject As sampleDataGridViewNumberTextBoxColumn = DirectCast(MyBase.Clone, sampleDataGridViewNumberTextBoxColumn)
cloneObject.MinValue = Me.MinValue
cloneObject.MaxValue = Me.MaxValue
cloneObject.CellValueType = Me.CellValueType
Return cloneObject
End Function
Private Sub SetMaxLength( _
ByVal format As String, _
ByVal minValue As Decimal, _
ByVal maxValue As Decimal)
Dim formattedMinValue As String = minValue.ToString(format)
Dim formattedMaxValue As String = maxValue.ToString(format)
If formattedMinValue.Length > formattedMaxValue.Length Then
MyBase.MaxInputLength = formattedMinValue.Length
Else
MyBase.MaxInputLength = formattedMaxValue.Length
End If
End Sub
<defaultvalue(gettype(decimal),> _
Public Property MinValue() As Decimal
Get
Return _minValue
End Get
Set(ByVal value As Decimal)
_minValue = value
SetMaxLength(Me.DefaultCellStyle.Format, _minValue, _maxValue)
End Set
End Property
<defaultvalue(gettype(decimal),> _
Public Property MaxValue() As Decimal
Get
Return _maxValue
End Get
Set(ByVal value As Decimal)
_maxValue = value
SetMaxLength(Me.DefaultCellStyle.Format, _minValue, _maxValue)
End Set
End Property
Public Shadows Property DefaultCellStyle() As DataGridViewCellStyle
Get
Return MyBase.DefaultCellStyle
End Get
Set(ByVal value As DataGridViewCellStyle)
MyBase.DefaultCellStyle = value
SetMaxLength(Me.DefaultCellStyle.Format, _minValue, _maxValue)
End Set
End Property
<browsable(false)> _
Public Shadows ReadOnly Property MaxInputLength() As Decimal
Get
Return MyBase.MaxInputLength
End Get
End Property
Public Enum Type
Number
Code
End Enum
End Class
Public Class sampleDataGridViewNumberTextBoxCell
Inherits System.Windows.Forms.DataGridViewTextBoxCell
Public Overrides ReadOnly Property EditType() As System.Type
Get
Return GetType(sampleDataGridViewNumberTextBoxEditingControl)
End Get
End Property
End Class
Public Class sampleDataGridViewNumberTextBoxEditingControl
Inherits System.Windows.Forms.DataGridViewTextBoxEditingControl
Private WM_PASTE As Integer = &H302
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_PASTE Then
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.Text) Then
Dim clipboardString As String = iData.GetData(DataFormats.Text).ToString
If Not System.Text.RegularExpressions.Regex.IsMatch(clipboardString, "^\d+$") Then
Return
End If
End If
End If
MyBase.WndProc(m)
End Sub
End Class
This code i read from internet.Hope this help .