By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

System.Drawing.StringAlignment.Far with Datagrid

P: n/a
Hi,

I have a problem with alignment with a datagrid.
When I use the SF variable with g.DrawString function, my first Decimal
Column is merged with the previous so my last column is blank.
If I don't use the SF variable everything is ok except that my decimal
values are not aligned on the right.

Do I miss something ?

Stan
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As
Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal
backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim e As DataGridFormatCellEventArgs

e = New DataGridFormatCellEventArgs(rowNum, Me._col,
Me.DataGridTableStyle.DataGrid.Font, backBrush, foreBrush)
RaiseEvent SetCellFormat(Me, e)
If e.UseBaseClassDrawing Then
MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight)
Else
g.FillRectangle(e.BackBrush, bounds)
If Me.GetColumnValueAtRow(source, rowNum).GetType.ToString =
"System.Decimal" Then
Dim SF As New System.Drawing.StringFormat
SF.Alignment = System.Drawing.StringAlignment.Far
g.DrawString(FormatNumber(Me.GetColumnValueAtRow(s ource, rowNum),
2), e.TextFont, e.ForeBrush, bounds.X, bounds.Y, SF)
Else
g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, e.ForeBrush, bounds.X, bounds.Y)
End If
End If
If (e.TextFont Is Me.DataGridTableStyle.DataGrid.Font) = False Then
e.TextFont.Dispose()
End If
End Sub
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.