Bonsoir
Je cherche à mettre une barre de progression dans une cellule d'un DataGridView.
Voici mon code :

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
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.ColumnIndex != 2)
                return;
            if (e.RowIndex < 0)
                return;
            ProgressBar pb = new ProgressBar();
            const int margin = 4;
 
            pb.Width = e.CellBounds.Right - e.CellBounds.Left - (margin * 2);
            pb.Value = (int)e.Value;
            Bitmap bmp = new Bitmap(pb.Width, pb.Height);
            pb.Update();
            pb.DrawToBitmap(bmp, pb.ClientRectangle);
            e.Graphics.DrawImage(bmp, new Point(e.CellBounds.X +margin, ((e.CellBounds.Bottom - e.CellBounds.Top - pb.Height) / 2) + e.CellBounds.Top));
            e.Handled = true;
        }
La barre de progression est bien là, sa valeur est bien à 50 mais visuellement la barre est à 0.
Pourquoi et comment corriger ça ?