Connecting Tech Pros Worldwide Forums | Help | Site Map

Text limit on DataGrid Column

Aaron Smith
Guest
 
Posts: n/a
#1: Nov 21 '05
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Text limit on DataGrid Column


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

------------------------

"Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
news:8lLkd.7619$_E1.6614@newssvr16.news.prodigy.co m...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.


Ken Tucker [MVP]
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Text limit on DataGrid Column


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

------------------------

"Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
news:8lLkd.7619$_E1.6614@newssvr16.news.prodigy.co m...
Is there a way to put a limit on the text size of a datagrid column?

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.


Aaron Smith
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Text limit on DataGrid Column


That works perfectly, Ken. Thank you very much.

Ken Tucker [MVP] wrote:[color=blue]
> 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
>
> ------------------------
>
> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
> news:8lLkd.7619$_E1.6614@newssvr16.news.prodigy.co m...
> Is there a way to put a limit on the text size of a datagrid column?
>
> Thanks,
> Aaron[/color]


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Aaron Smith
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Text limit on DataGrid Column


That works perfectly, Ken. Thank you very much.

Ken Tucker [MVP] wrote:[color=blue]
> 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
>
> ------------------------
>
> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
> news:8lLkd.7619$_E1.6614@newssvr16.news.prodigy.co m...
> Is there a way to put a limit on the text size of a datagrid column?
>
> Thanks,
> Aaron[/color]


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Rulin Hong
Guest
 
Posts: n/a
#6: Nov 21 '05

re: Text limit on DataGrid Column


Simply set DataGridTextBoxColumn.TextBox.MaxLength property in code
Rulin Hong
Guest
 
Posts: n/a
#7: Nov 21 '05

re: Text limit on DataGrid Column


Simply set DataGridTextBoxColumn.TextBox.MaxLength property in code
Closed Thread