Hallo,
in einem DGV habe ich mit folgendem Code Zellen verbunden:
Dim pCell As HMergedCell
Dim nOffset As Integer
Dim i As Integer, j As Integer
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewCellEventArgs) Handles _
DataGridView1.CellEndEdit
....
For k As Integer = nOffset To nOffset + 3
Me.DataGridView1.Rows(i).Cells(k) = New HMergedCell()
pCell = DirectCast(Me.DataGridView1.Rows(i).Cells(k), _
HMergedCell)
pCell.LeftColumn = nOffset
pCell.RightColumn = nOffset + 3
Next
nOffset += 7
...
End Sub
Public Class HMergedCell
Inherits DataGridViewTextBoxCell
Private m_nLeftColumn As Integer = 0
Private m_nRightColumn As Integer = 0
Public Property LeftColumn() As Integer
Get
Return m_nLeftColumn
End Get
Set(ByVal value As Integer)
m_nLeftColumn = value
End Set
End Property
Public Property RightColumn() As Integer
Get
Return m_nRightColumn
End Get
Set(ByVal value As Integer)
m_nRightColumn = value
End Set
End Property
Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal _
clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal _
rowIndex As Integer, ByVal cellState As DataGridViewElementStates, _
ByVal value As Object, _
ByVal formattedValue As Object, ByVal errorText As String, ByVal _
cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As _
DataGridViewAdvancedBorderStyle, ByVal paintParts As _
DataGridViewPaintParts)
Try
Dim mergeindex As Integer = ColumnIndex - m_nLeftColumn
Dim i As Integer
Dim nWidth As Integer
Dim nWidthLeft As Integer
Dim strText As String
Dim pen As New Pen(Brushes.Black)
' Draw the background
graphics.FillRectangle(New SolidBrush(System.Drawing.Color.White), _
cellBounds)
' Draw the separator for rows
graphics.DrawLine(New Pen(New SolidBrush( _
SystemColors.ControlDark)), cellBounds.Left, cellBounds.Bottom - _
1, cellBounds.Right, cellBounds.Bottom - 1)
' Draw the right vertical line for the cell
If ColumnIndex = m_nRightColumn Then
graphics.DrawLine(New Pen(New SolidBrush( _
SystemColors.ControlDark)), cellBounds.Right - 1, _
cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom)
End If
' Draw the text
Dim rectDest As RectangleF = RectangleF.Empty
Dim sf As New StringFormat()
sf.Alignment = StringAlignment.Near
sf.LineAlignment = StringAlignment.Near
sf.Trimming = StringTrimming.EllipsisCharacter
' Determine the total width of the merged cell
nWidth = 0
For i = m_nLeftColumn To m_nRightColumn
nWidth += Me.OwningRow.Cells(i).Size.Width
Next
' Determine the width before the current cell.
nWidthLeft = 0
For i = m_nLeftColumn To ColumnIndex - 1
nWidthLeft += Me.OwningRow.Cells(i).Size.Width
Next
' Retrieve the text to be displayed
strText = Me.OwningRow.Cells(m_nLeftColumn).Value.ToString()
rectDest = New RectangleF(cellBounds.Left - nWidthLeft, _
cellBounds.Top, nWidth, cellBounds.Height)
graphics.DrawString(strText, New Font("Arial", 10, _
FontStyle.Regular), Brushes.Black, rectDest, sf)
Catch ex As Exception
Trace.WriteLine(ex.ToString())
End Try
End Sub
End Class Wie kann ich den Zellverbund wieder aufheben, bzw. die Zeile ohne Verbund neu zeichnen?
Bitte um Hilfe
Danke
Christian
Danke für die Hilfe
Gruß Christian |