473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dbgird

Hi,

I have poulated my grid but want to restrict users from
entering only date in the second col with the specified
format as in MM/DD/YY.

How do I set Character Casing for the third col of my grid.

Tnx

Nov 21 '05 #1
1 848
Hi,

Make a new datagridtextboxcolumn. In the edit event set the
charactercasing for the textbox. Here is a sample.
Public Class HeaderAndDataAlignColumn
Inherits DataGridTextBoxColumn

Private mTxtAlign As HorizontalAlignment = HorizontalAlignment.Left
Private mDrawTxt As New StringFormat

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.TextAlign = mTxtAlign
MyBase.TextBox.CharacterCasing = CharacterCasing.Upper
End Sub

Protected Overloads Overrides Sub Paint(ByVal g As
System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer,
ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As
System.Drawing.Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle(backBrush, bounds)

'draw the value
Dim s As String = Me.GetColumnValueAtRow([source],
rowNum).ToString()
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, MyBase.TextBox.Font, foreBrush,
RectangleF.op_Implicit(r), _
mDrawTxt)
End Sub

Public Property DataAlignment() As HorizontalAlignment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlignment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlignment.Center Then
mDrawTxt.Alignment = StringAlignment.Center
ElseIf mTxtAlign = HorizontalAlignment.Right Then
mDrawTxt.Alignment = StringAlignment.Far
Else
mDrawTxt.Alignment = StringAlignment.Near
End If
End Set
End Property

End Class

Ken
--------------------

"Paps" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hi,

I have poulated my grid but want to restrict users from
entering only date in the second col with the specified
format as in MM/DD/YY.

How do I set Character Casing for the third col of my grid.

Tnx
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.