Hi,
Here is a column style that i wrote that allows you set set max
length and character casing. Use it instead of a datagridtextbox column in
your datagrid tablestyle.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.ComponentModel
<DataSysDescription("This column style adds Max length and Character Casing
to the datagrid textbox column")> _
Public Class ExtendedTextBoxColumn
Inherits DataGridTextBoxColumn
Dim mccText As CharacterCasing = CharacterCasing.Normal
Dim mintMaxLength As Integer = 0
<DataSysDescription("Upper, Lower, or Normal")> _
Public Property TextCharacterCasing() As CharacterCasing
Get
Return mccText
End Get
Set(ByVal Value As CharacterCasing)
mccText = Value
End Set
End Property
<DataSysDescription("Max Length of Text. Use 0 to retrieve full text")> _
Public Property MaxLength() As Integer
Get
Return mintMaxLength
End Get
Set(ByVal Value As Integer)
mintMaxLength = 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.CharacterCasing = mccText
If mintMaxLength > 0 Then MyBase.TextBox.MaxLength = mintMaxLength
End Sub
Protected Overrides Function GetColumnValueAtRow(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
Dim obj As String
Dim strReturn As String
obj = MyBase.GetColumnValueAtRow(source, rowNum).ToString
Select Case mccText
Case CharacterCasing.Lower
strReturn = obj.ToLower
Case CharacterCasing.Upper
strReturn = obj.ToUpper
Case CharacterCasing.Normal
strReturn = obj
End Select
If mintMaxLength > 0 And strReturn.Length > mintMaxLength Then
strReturn = strReturn.Substring(0, mintMaxLength)
End If
Return strReturn
End Function
End Class
Ken
------------------------
Is there a way to put a limit on the text size of a datagrid column?
Thanks,
Aaron