Bold AND AlignRight in DataGridCell

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I'm able to set the Font in a Datagrid-Cell to Bold with
g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString, e.TextFont,
e.ForeBrush, bounds.X, bounds.Y)

and to Align the text to Right with
MyBase.Paint(g, bounds, source, rowNum, e.BackBrush, e.ForeBrush,
e.AlignRight)

But I can't figure out how to set it to Bold AND Align Right.

Anybody knows how to do this?

Thanks a lot in advance,

Pieter
 
Hi,

My guess is to modify the DrawString code in the PaintText override so it
can take the required alignment into account.
 
Hm, I did it like this: it seems to work fine.

If e.AlignRight Then

Dim intAlign As Integer

Dim sf As StringFormat

sf = New StringFormat(StringFormat.GenericTypographic)

Dim size As SizeF

size = g.MeasureString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, 500, sf)

intAlign = Me.DataGridTableStyle.GridColumnStyles.Item(Me._col).Width -
size.Width - 5

g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, e.ForeBrush, bounds.X + intAlign, bounds.Y + 2)

Else

g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString,
e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2)

End If


Thanks for the suggestion. although I hoped to have a 'nicer' way, hehe :-)


Dmitriy Lapshin said:
Hi,

My guess is to modify the DrawString code in the PaintText override so it
can take the required alignment into account.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

DraguVaso said:
Hi,

I'm able to set the Font in a Datagrid-Cell to Bold with
g.DrawString(Me.GetColumnValueAtRow(source, rowNum).ToString, e.TextFont,
e.ForeBrush, bounds.X, bounds.Y)

and to Align the text to Right with
MyBase.Paint(g, bounds, source, rowNum, e.BackBrush, e.ForeBrush,
e.AlignRight)

But I can't figure out how to set it to Bold AND Align Right.

Anybody knows how to do this?

Thanks a lot in advance,

Pieter
 
Back
Top