Datagridview column header merge vb.net

  • Thread starter Thread starter GEEDER
  • Start date Start date
G

GEEDER

Guest
hi! I'm merging my columns in datagridview. I got the code here but there is a problem.

here is the scenario. I have 18 columns and I want to start merging from 4th column to last (15 columns in total merge by 3)

the problem is not all string in my string list is painted

Dim _MainColumns() As String = {"Socialized", "Affordable", "Middle Income", "High End", "Low Affordable"}

"Socialized" is not shown.

1358954.png

Here is the code in dgvMain_Paint:

Dim _MainColumns() As String = {"Socialized", "Affordable", "Middle Income", "High End", "Low Affordable"}
Dim x As Integer = 3
Dim ColCounter As Integer = dgvMain.ColumnCount - 3
While x < ColCounter
Dim r1 As Rectangle = dgvMain.GetCellDisplayRectangle(x, -1, True)
Dim w2 As Integer = dgvMain.GetCellDisplayRectangle(x + 1, -1, True).Width
r1.X += 1
r1.Y += 1
r1.Width = r1.Width + w2 + w2 - 3
r1.Height = r1.Height / 2 - 2
e.Graphics.FillRectangle(New SolidBrush(dgvMain.ColumnHeadersDefaultCellStyle.BackColor), r1)
Dim format As New StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(_MainColumns(x \ 3), dgvMain.ColumnHeadersDefaultCellStyle.Font, New SolidBrush(dgvMain.ColumnHeadersDefaultCellStyle.ForeColor), r1, format)
x += 3
End While

hope you can help thanks.

this is my reference : merge two column headers



GEEDER

Continue reading...
 
Back
Top