How to merge Datagrid view cell
  • How to merge Datagrid view cell
  • 1 Comment sorted by


  • Private Sub gv_CellPainting(ByVal sender As System.Object, ByVal e As

    System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles gv.CellPainting
    If e.ColumnIndex = 0 AndAlso e.RowIndex <> -1 Then

    Using gridBrush As Brush = New SolidBrush(Me.gv.GridColor), backColorBrush As Brush = New SolidBrush(e.CellStyle.BackColor)


    Using gridLinePen As Pen = New Pen(gridBrush)

    e.Graphics.FillRectangle(backColorBrush, e.CellBounds)


    If e.RowIndex < gv.Rows.Count - 2 AndAlso gv.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Value.ToString() <> e.Value.ToString() Then
    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1)
    End If


    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom)


    If Not e.Value Is Nothing Then
    If e.RowIndex > 0 AndAlso gv.Rows(e.RowIndex - 1).Cells(e.ColumnIndex).Value.ToString() = e.Value.ToString() Then

    Else

    If e.Value <> "" Then
    ' e.Graphics.DrawString(CType(e.Value, String), e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5, StringFormat.GenericDefault)
    e.Graphics.DrawString(CType(e.Value, String), New Font("Tahoma", 15, FontStyle.Regular), Brushes.Black, e.CellBounds.X + 14, e.CellBounds.Y + 2, StringFormat.GenericDefault)

    End If

    End If
    End If

    e.Handled = True
    End Using
    End Using

    End If




    End Sub

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

    Optimum Creative