Katunigan
September 22nd, 2004, 02:43 PM
Hi Gurus,
I am trying to allign my numeric data in my datagrid to the right? does anyone have a clue?
Thank you.
Boumxyz2
September 22nd, 2004, 02:57 PM
You have to define a gridtablestyle and then a gridcolumnstyle then you can access the textbox if you add a text
ReDim Preserve ColumnText(Columntextindex)
ColumnText(ColumnText.GetUpperBound(0)) = New DataGridTextBoxColumn
Dim temp As DataGridTextBoxColumn
temp = ColumnText(ColumnText.GetUpperBound(0))
temp.MappingName = "ColumnName you want"
temp.Alignment = HorizontalAlignment.Center
temp.HeaderText = "TEST"
temp.TextBox.MaxLength = 26
Temp.TextBox.Tag = 255
temp.Width = 150
Columntextindex = Columntextindex + 1
athanikos
March 8th, 2005, 02:49 PM
this will allign the text not the column header
you should replace
firend withEvents DatagridTextBoxColumn as DatagrdTextboxColumn
with
firend withEvents DatagridTextBoxColumn as DataGridTextBoxCurrency
DatagridTextBoxColumn.... = new DatagrdTextboxColumn
with
DatagridTextBoxColumn.... = new DataGridTextBoxCurrency
Imports System.Drawing
Imports System.Windows.Forms
Public Class DataGridTextBoxCurrency
Inherits DataGridTextBoxColumn
Private mTxtAlign As HorizontalAlignment = HorizontalAlignment.Right
Private mDrawTxt As New StringFormat
Public Sub New()
MyBase.New()
mDrawTxt.Alignment = StringAlignment.Far
End Sub
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
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