J
Jon
Hi all,
I am working on a DataGridView that has "merged cells" using a rectangle
placed in a paint routine.
code follows:
Private Sub dgvWalls_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles dgvWalls.Paint
Dim fnt As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
'setup variables for vertical cells
Dim sdp As System.Drawing.Point '
Dim sds As System.Drawing.Size
Dim str As String
Dim lefts, tops, i, x As Integer
Dim strlen As SizeF
For i = 0 To dgvWalls.RowCount - 1
Dim rct(i) As Rectangle
dgvWalls.CurrentCell = dgvWalls(0, i) 'select first cell
If dgvWalls.CurrentCell.Value <> "" Then 'no string then skip it
str = dgvWalls.CurrentCell.Value.ToString ' put the text in a string
strlen = e.Graphics.MeasureString(str, dgvWalls.Font) ' set string length
sdp.X = dgvWalls.GetRowDisplayRectangle(i, True).X +
dgvWalls.RowHeadersWidth
sdp.Y = dgvWalls.GetRowDisplayRectangle(i, True).Y
sds.Height = dgvWalls.GetRowDisplayRectangle(i, True).Height - 1 ' subtract
1 to show line
x = dgvWalls.Columns(0).Width + dgvWalls.Columns(1).Width
sds.Width = x - 1 ' subtract 1 to show line
rct(i).Location = sdp
rct(i).Size = sds
lefts = (rct(i).Width / 2) - (strlen.Width / 2)
tops = rct(i).Top + ((rct(i).Height / 2) - (strlen.Height / 2))
e.Graphics.FillRectangle(Brushes.White, rct(i)) 'Merge 2 cells
e.Graphics.DrawString(str, fnt, Brushes.Black, lefts, tops)
Else
End If
Next
End Sub
______________________
Routine works fabulous except the paint routine seems to go into a loop.
Can you see my error. For the life of me I can't.
Thanks
I am working on a DataGridView that has "merged cells" using a rectangle
placed in a paint routine.
code follows:
Private Sub dgvWalls_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles dgvWalls.Paint
Dim fnt As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
'setup variables for vertical cells
Dim sdp As System.Drawing.Point '
Dim sds As System.Drawing.Size
Dim str As String
Dim lefts, tops, i, x As Integer
Dim strlen As SizeF
For i = 0 To dgvWalls.RowCount - 1
Dim rct(i) As Rectangle
dgvWalls.CurrentCell = dgvWalls(0, i) 'select first cell
If dgvWalls.CurrentCell.Value <> "" Then 'no string then skip it
str = dgvWalls.CurrentCell.Value.ToString ' put the text in a string
strlen = e.Graphics.MeasureString(str, dgvWalls.Font) ' set string length
sdp.X = dgvWalls.GetRowDisplayRectangle(i, True).X +
dgvWalls.RowHeadersWidth
sdp.Y = dgvWalls.GetRowDisplayRectangle(i, True).Y
sds.Height = dgvWalls.GetRowDisplayRectangle(i, True).Height - 1 ' subtract
1 to show line
x = dgvWalls.Columns(0).Width + dgvWalls.Columns(1).Width
sds.Width = x - 1 ' subtract 1 to show line
rct(i).Location = sdp
rct(i).Size = sds
lefts = (rct(i).Width / 2) - (strlen.Width / 2)
tops = rct(i).Top + ((rct(i).Height / 2) - (strlen.Height / 2))
e.Graphics.FillRectangle(Brushes.White, rct(i)) 'Merge 2 cells
e.Graphics.DrawString(str, fnt, Brushes.Black, lefts, tops)
Else
End If
Next
End Sub
______________________
Routine works fabulous except the paint routine seems to go into a loop.
Can you see my error. For the life of me I can't.
Thanks