Salut les amis
Je développe une application en vb.net et j'ai un petit problème, je veux afficher une icône dans la zone montrée sur l'image suivante :
Pièce jointe 138218
Merci d'avance.
Version imprimable
Salut les amis
Je développe une application en vb.net et j'ai un petit problème, je veux afficher une icône dans la zone montrée sur l'image suivante :
Pièce jointe 138218
Merci d'avance.
soit tricher en disant de ne pas mettre la colonne header et faire une colonne 0 qui contient l'icone
soit faire une classe qui hérite datagridviewheadercell capable de draw une image et l'utiliser à la création des lignes
Bonjour
peut etre ici
http://social.msdn.microsoft.com/For...msdatacontrols
Salut les amis
merci pour vos réponses, en cherchant bien j'ai trouvé un code qui sert à ajouter une image dans le CellHeader, mais le code est en C#, voilà le code :
j'ai converti en vb.net mais quand j’atteins Properties.Resources...... le code n'ai pas reconnue en vb.netCode:
1
2
3
4
5
6
7
8
9 private void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == -1 && e.RowIndex > -1) { e.Handled = true; e.PaintBackground(e.CellBounds, true); e.Graphics.DrawImage(Properties.Resources.yourIMAGE, new Rectangle(e.CellBounds.Left + 5, e.CellBounds.Top + 5, e.CellBounds.Width - 10, e.CellBounds.Height - 10)); } }
Si quelqu'un pouvait me donner un exemple " e.Graphics.DrawImage(..........)
Merci encore
peut etre ainsi
Code:
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 Private myicon As Image Public Sub New() ' This call is required by the designer. InitializeComponent() myicon = CType(My.Resources.ResourceManager.GetObject("iconname"), Bitmap) ' Add any initialization after the InitializeComponent() call. End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' DataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders For iter = 0 To 3 DataGridView1.Columns.Add("col" & iter.ToString, " ") Next For iter = 0 To 10 DataGridView1.Rows.Add() DataGridView1.Rows.Item(iter).Height = myicon.Height DataGridView1.Rows.Item(iter).Cells(0).Value = " toto" DataGridView1.Rows.Item(iter).Cells(1).Value = " toto" DataGridView1.Rows.Item(iter).Cells(2).Value = " toto" DataGridView1.Rows.Item(iter).Cells(3).Value = " toto" Next DataGridView1.AutoSize = True DataGridView1.AutoResizeColumns() End Sub Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint Dim x As Integer x = DataGridView1.GetCellDisplayRectangle(0, 0, False).Top For iter = 1 To DataGridView1.Rows.Count - 1 e.Graphics.DrawImage(myicon, New Point(0, x)) x += myicon.Height Next End Sub End Class
Salut les amis, j'ai réussi à afficher l'icône voilà le code que j'ai utilisé :
J'ai ajouté l'icône dont le nom et Medi dans les ressources du projet.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Private myicon As Image Public Sub New() ' This call is required by the designer. InitializeComponent() myicon = CType(My.Resources.ResourceManager.GetObject("Medi"), Bitmap) ' Add any initialization after the InitializeComponent() call. End Sub Private Sub Produitgrid_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles Produitgrid.CellPainting If e.ColumnIndex = -1 And e.RowIndex > -1 Then e.Handled = True e.PaintBackground(e.CellBounds, True) e.Graphics.DrawImage(myicon, New Rectangle(e.CellBounds.Left + 5, e.CellBounds.Top + 5, e.CellBounds.Width - 10, e.CellBounds.Height - 10)) End If
Merci encore