/// <summary> /// Handles X2 "Progress" BeforeCellPaint events /// </summary> /// <param name="sender">DataGridViewProgressBarXColumn</param> /// <param name="e">BeforeCellPaintEventArgs</param> void X2Progress_BeforeCellPaint(object sender, BeforeCellPaintEventArgs e) { DataGridViewProgressBarXColumn pbc = sender as DataGridViewProgressBarXColumn; if (pbc != null) { switch (pbc.Value) { case 0: pbc.Text = "Not Started"; break; case 100: pbc.Text = "Completed"; pbc.ColorTable = eProgressBarItemColor.Normal; break; default: pbc.Text = ""; pbc.ColorTable = eProgressBarItemColor.Paused; break; } if (pbc.Value < 30) { pbc.ColorTable = eProgressBarItemColor.Error; } } }
private void proccessBar() { if (dataGridView1.RowCount <= 0) { return; } dataGridView1.Columns["id"].Visible = false; DataGridViewProgressBarXColumn rowsProgressBar; int columnsNumber = dataGridView1.Columns.Count - 1; for (int i = 0; i < dataGridView1.RowCount; i++) { rowsProgressBar = new DataGridViewProgressBarXColumn(); //rowsProgressBar.Width = 10; Random random = new Random(); int s = random.Next(0, 100); dataGridView1.Rows[i].Cells[0].Value = s; dataGridView1.Rows[i].Cells[0].ToolTipText = s.ToString() + "%"; if (dataGridView1.Rows[i].Cells[columnsNumber].Value.ToString().Equals("否")) { dataGridView1.Rows[i].Cells[columnsNumber].Style.ForeColor = Color.Red; } else { dataGridView1.Rows[i].Cells[columnsNumber].Style.ForeColor = Color.Green; } } }
/// <summary> /// Initializes our X2 "Progress" environment /// </summary> private void X2Progress_Initialize() { DataGridViewProgressBarXColumn pb = dataGridViewX2.Columns["Progress"] as DataGridViewProgressBarXColumn; // Hook onto the BeforeCellPaint event so we can // demonstrate cell customization if (pb != null) { pb.BeforeCellPaint += X2Progress_BeforeCellPaint; } }