DatagridTextBoxColumn- max length

  • Thread starter Thread starter Agnes
  • Start date Start date
I know how to set the max length for the datatable.
dtInvoice.columns.item("description").maxlength = 40

However, the effect as not good as textbox.
The user can input the 50 charactrers, as he/she press 'enter', there is a
messagebox prompt out.
I think it is not good for the user.. Any other idea ?
 
Hi,

Here is a class that inherits from a datagridtextboxcolumn that should
work.

Public Class MaxLengthColumn
Inherits DataGridTextBoxColumn

Private mintLen As Integer = 256

Public Property MaxLength() As Integer
Get
Return mintLen
End Get
Set(ByVal Value As Integer)
mintLen = Value
End Set
End Property

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal
instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
MyBase.TextBox.MaxLength = mintLen
End Sub


End Class


Ken
-------------------
 
Back
Top