Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...