Controls [vb.net] DataGridView 헤더 병합
페이지 정보

본문
        dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        dgv.ColumnHeadersHeight *= 2
        AddHandler dgv.Paint, Sub(ByVal sd As Object, ByVal ee As PaintEventArgs)
                                  Dim monthes As String() = {"Total", "Correct", "Wrong", "Score"}
                                  Dim j As Integer = 3
                                  Dim pDGV As DataGridView = CType(sd, DataGridView)
                                  Try
                                      While j < 18
                                          Dim r1 As Rectangle = pDGV.GetCellDisplayRectangle(j, -1, True)
                                          Dim w2 As Integer = pDGV.GetCellDisplayRectangle(j + 1, -1, True).Width + pDGV.GetCellDisplayRectangle(j + 2, -1, True).Width + pDGV.GetCellDisplayRectangle(j + 3, -1, True).Width
                                          r1.X += 1
                                          r1.Y += 1
                                          r1.Width = r1.Width + w2 - 2
                                          r1.Height = r1.Height / 2 - 2
                                          '// e.Graphics.FillRectangle(New SolidBrush(DGV.ColumnHeadersDefaultCellStyle.BackColor), r1)
                                          If monthes((j - 3) / 4) = "Score" Then
                                              ee.Graphics.FillRectangle(New SolidBrush(Color.Black), r1)
                                          Else
                                              ee.Graphics.FillRectangle(New SolidBrush(Color.DarkGray), r1)
                                          End If
                                          ee.Graphics.DrawLine(New Pen(New SolidBrush(Color.LightCyan)), r1.Left, r1.Bottom - 1, r1.Right, r1.Bottom - 1)
                                          Dim format As New StringFormat()
                                          format.Alignment = StringAlignment.Center
                                          format.LineAlignment = StringAlignment.Center
                                          ee.Graphics.DrawString(monthes((j - 3) / 4), pDGV.ColumnHeadersDefaultCellStyle.Font, New SolidBrush(Color.White), r1, format)
                                          j += 4
                                      End While
                                  Catch ex As Exception
                                  End Try
                              End Sub
- 이전글[vb.net] ToString()와 같은 확장 메서드(Visual Basic) 21.05.06
- 다음글[vb.net] Merge DataGridView Cells / DataGridView 셀병합 21.05.02
댓글목록
등록된 댓글이 없습니다.





