|
-
Jan 8th, 2015, 07:47 PM
#1
Thread Starter
PowerPoster
[RESOLVED] graphics / paint issue with datagridview
Hi all,
The task at hand was to add group headings within my data in the datagridview (i.e., I needed to merge cells in particular rows). Since this is not a native feature of the DGV, after hours of searching I found some code that does the trick. I modified that code to suit my needs, and it works great except for one wrinkle: it places extra, cut off text at the top of the DGV (in/above the column header area) and I can't figure out how to get rid of it. This screen shot shows the problem:
http://thevbprogrammer.com/dgv.png
The code used to accomplish the merging, in the DGV's Paint event, is as follows:
Code:
Private Sub dgvAvailItems_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles dgvAvailItems.Paint
Dim fnt As Font
Dim brush As Drawing.Brush
For intRowX As Integer = 0 To dgvAvailItems.Rows.Count - 1
If dgvAvailItems.Rows(intRowX).Cells(14).Value <> "" Then
If dgvAvailItems.Rows(intRowX).Cells(14).Value = "W" Then
fnt = New Font("Tahoma", 10, FontStyle.Italic + FontStyle.Bold, GraphicsUnit.Point)
brush = Brushes.RoyalBlue
Else
fnt = New Font("Tahoma", 10, FontStyle.Bold, GraphicsUnit.Point)
brush = Brushes.Black
End If
Dim rct As Rectangle = dgvAvailItems.GetRowDisplayRectangle(intRowX, True)
rct.Height -= 1
Dim s As SizeF = e.Graphics.MeasureString(dgvAvailItems.Rows(intRowX).Cells(1).Value, dgvAvailItems.Font)
Dim lefts As Integer = (rct.Width / 2) - (s.Width / 2)
Dim tops As Integer = rct.Top + ((rct.Height / 2) - (s.Height / 2))
e.Graphics.FillRectangle(Brushes.White, rct)
e.Graphics.DrawString(dgvAvailItems.Rows(intRowX).Cells(1).Value, fnt, brush, 2, tops)
End If
Next
End Sub
Any help would be appreciated. Thanks.
Last edited by BruceG; Jan 9th, 2015 at 11:26 AM.
Reason: resolved
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|