Bonjour,

Désolé de vous relancer sur ce sujet mais je n'ai pas eu de réponse claire.
Le but est donc de pouvoir avoir un système de multi headers dans un datagridview : le header supérieur étant divisé par x headers inférieurs :

| AA | BB |
|1 |2|1 |2|

La solution que j'adopte passe par un repaint.
Voici mon code (qui ne marche pas et dont on me dit qu'il devrait marcher...) :

Dans une class :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Public Class MyDGVColumn
    Inherits DataGridViewTextBoxColumn
 
    Public Sub New()
        MyBase.HeaderCell = New MyHeadCell
    End Sub
 
End Class
 
 
Public Class MyHeadCell
    Inherits DataGridViewColumnHeaderCell
 
    Public Sub New()
 
    End Sub
 
    Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, _
        ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal dataGridViewElementState As System.Windows.Forms.DataGridViewElementStates, _
        ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, _
        ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
        MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
 
 
 
        Dim Monthes() As String = {"Jan", "Feb", "Mar"}
        For A As Int32 = 0 To 5
 
            Dim Rect As Rectangle = cellBounds
 
            Rect.X += 1
            Rect.Y += 1
 
            Rect.Width = Rect.Width * 2 - 2
 
            Rect.Height = Rect.Height / 2 - 2
 
            graphics.FillRectangle(Brushes.Salmon, Rect)
 
            Dim Format As New StringFormat()
            Format.Alignment = StringAlignment.Center
            Format.LineAlignment = StringAlignment.Center
 
            graphics.DrawString(Monthes(A / 2), cellStyle.Font, Brushes.Purple, Rect, Format)
 
            A += 1
        Next
    End Sub
End Class
Dans un formulaire (où j'ai posé un datagridview) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim MyCol As New MyDGVColumn
 
 
        With DataGridView1
            .Columns.Add(MyCol.Name, "Win")
            .Columns.Add(MyCol.Name, "Loss")
            .Columns.Add(MyCol.Name, "Win")
            .Columns.Add(MyCol.Name, "Loss")
            .Columns.Add(MyCol.Name, "Win")
            .Columns.Add(MyCol.Name, "Loss")
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
            .ColumnHeadersHeight = DataGridView1.ColumnHeadersHeight * 2
        End With
 
    End Sub
 
 
End Class
En fait l'événement Paint n'est jamais levé...

Merci de m'éclairer !
Alexandre