G
George Waters
Guest
Hi,
I have the following problem, I use CellPainting to merge cells, but when I click on the top merged area, it shows the cell like this:
This is my code:
Private Sub dg_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles dg.CellPainting
If e.RowIndex > 0 Then
If e.ColumnIndex = 10 Or e.ColumnIndex = 11 Then
Dim cell1 As DataGridViewCell = dg(12, e.RowIndex - 1)
Dim cell2 As DataGridViewCell = dg(12, e.RowIndex)
If cell1.Value = cell2.Value Then
Using gridBrush As Brush = New SolidBrush(dgLotes.GridColor), backColorBrush As Brush = New SolidBrush(Color.FromArgb(190, 209, 165))
Using gridLinePen As Pen = New Pen(gridBrush)
Dim Rect As New Rectangle(dg.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex - 1, False).Left, _
dg.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex - 1, False).Top, _
dg(e.ColumnIndex, e.RowIndex - 1).Size.Width, _
dg(e.ColumnIndex, e.RowIndex - 1).Size.Height + dg(e.ColumnIndex, e.RowIndex).Size.Height)
e.Graphics.FillRectangle(backColorBrush, Rect)
e.Graphics.DrawLine(gridLinePen, Rect.Left, Rect.Bottom - 1, Rect.Right - 1, Rect.Bottom - 1)
e.Graphics.DrawLine(gridLinePen, Rect.Right - 1, Rect.Top, Rect.Right - 1, Rect.Bottom)
e.Graphics.DrawString(CType(dg(e.ColumnIndex, e.RowIndex - 1).Value, String), _
e.CellStyle.Font, Brushes.Black, Rect.X + (Rect.Width / 2), Rect.Y + (Rect.Height / 3))
e.Handled = True
End Using
End Using
End If
End If
End If
End Sub
What am I doing wrong?
Regards.
G.Waters
Continue reading...
I have the following problem, I use CellPainting to merge cells, but when I click on the top merged area, it shows the cell like this:
This is my code:
Private Sub dg_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles dg.CellPainting
If e.RowIndex > 0 Then
If e.ColumnIndex = 10 Or e.ColumnIndex = 11 Then
Dim cell1 As DataGridViewCell = dg(12, e.RowIndex - 1)
Dim cell2 As DataGridViewCell = dg(12, e.RowIndex)
If cell1.Value = cell2.Value Then
Using gridBrush As Brush = New SolidBrush(dgLotes.GridColor), backColorBrush As Brush = New SolidBrush(Color.FromArgb(190, 209, 165))
Using gridLinePen As Pen = New Pen(gridBrush)
Dim Rect As New Rectangle(dg.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex - 1, False).Left, _
dg.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex - 1, False).Top, _
dg(e.ColumnIndex, e.RowIndex - 1).Size.Width, _
dg(e.ColumnIndex, e.RowIndex - 1).Size.Height + dg(e.ColumnIndex, e.RowIndex).Size.Height)
e.Graphics.FillRectangle(backColorBrush, Rect)
e.Graphics.DrawLine(gridLinePen, Rect.Left, Rect.Bottom - 1, Rect.Right - 1, Rect.Bottom - 1)
e.Graphics.DrawLine(gridLinePen, Rect.Right - 1, Rect.Top, Rect.Right - 1, Rect.Bottom)
e.Graphics.DrawString(CType(dg(e.ColumnIndex, e.RowIndex - 1).Value, String), _
e.CellStyle.Font, Brushes.Black, Rect.X + (Rect.Width / 2), Rect.Y + (Rect.Height / 3))
e.Handled = True
End Using
End Using
End If
End If
End If
End Sub
What am I doing wrong?
Regards.
G.Waters
Continue reading...