Setting alternatingback color for grid with combobox column

smriti

Regular
Joined
Jan 7, 2005
Messages
54
Dear Friends,

I am using combobox column in datagrid.
And I am setting AlternatingBackColor of grid to Blue.
But the combobox column is not displaying the AlternatingBackColor.
How to do this.

The following is the paint text method i used.

Private Sub PaintText(ByVal g As Graphics, _
ByVal Bounds As Rectangle, _
ByVal Text As String, _
ByVal AlignToRight As Boolean)
Dim BackBrush As Brush
BackBrush = New SolidBrush(Me.DataGridTableStyle.BackColor)
Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor)
PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
End Sub

Private Sub PaintText(ByVal g As Graphics, _
ByVal TextBounds As Rectangle, _
ByVal Text As String, _
ByVal BackBrush As Brush, _
ByVal ForeBrush As Brush, _
ByVal AlignToRight As Boolean)


Dim Rect As Rectangle = TextBounds
Dim RectF As RectangleF = RectF.op_Implicit(Rect) ' Convert to RectangleF
Dim Format As StringFormat = New StringFormat

If AlignToRight Then
Format.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If

Select Case Me.Alignment
Case Is = HorizontalAlignment.Left
Format.Alignment = StringAlignment.Near
Case Is = HorizontalAlignment.Right
Format.Alignment = StringAlignment.Far
Case Is = HorizontalAlignment.Center
Format.Alignment = StringAlignment.Center
End Select

Format.FormatFlags = Format.FormatFlags Or StringFormatFlags.NoWrap
g.FillRectangle(Brush:=BackBrush, Rect:=Rect)

Rect.Offset(0, yMargin)
Rect.Height -= yMargin
g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format)
Format.Dispose()

End Sub


If BackBrush is given as SolidBrush(Me.DataGridTableStyle.AltrenatingBackColor)

then all the cells in the column are displaying in Blue.

How to do this.


Thanks.
 
Back
Top