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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewProgressBarCSharp
{
public partial class Form1 : Form
{
private DataClass dt;
private List<DataClass > ListData=new List<DataClass> ();
public Form1()
{
InitializeComponent();
populateDGV();
}
private void populateDGV()
{
for (int i = 0; i < 9; i++)
{
this.dt = new DataClass("Nom" + (i + 1).ToString(), (i + 1) * 10);
this.ListData.Add(dt);
}
this.dataGridView1.DataSource=this.ListData ;
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex != 1 )
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;
}
}
public class DataClass
{
public DataClass(string n, int num)
{
this.Name=n;
this.Account = num;
}
public string Name { get; set; }
public int Account { get; set; }
}
} |
Partager