Example E20007
Visible to All Users

WinForms Data Grid - Show progress text along with a progress bar in the exported document

This example creates a custom progress bar editor that can display its progress along with a progress bar:

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

WindowsApplication1/MyProgressBarControl.cs(vb)
C#
using DevExpress.XtraEditors; using DevExpress.XtraEditors.Drawing; using DevExpress.XtraEditors.Registrator; using DevExpress.XtraEditors.Repository; using DevExpress.XtraEditors.ViewInfo; using DevExpress.XtraPrinting; using System; using System.Drawing; using System.Drawing.Drawing2D; namespace WindowsApplication1 { public class MyProgressBarControl : ProgressBarControl { static MyProgressBarControl() { RepositoryItemMyProgressBarControl.RegisterMyProgressBarControl(); } public MyProgressBarControl() : base() { } public override string EditorTypeName { get { return RepositoryItemMyProgressBarControl.MyProgressBarControlName; } } public new RepositoryItemMyProgressBarControl Properties { get { return (RepositoryItemMyProgressBarControl)base.Properties; } } [UserRepositoryItem("RegisterMyProgressBarControl")] public class RepositoryItemMyProgressBarControl : RepositoryItemProgressBar { public const string MyProgressBarControlName = "MyProgressBarControl"; static RepositoryItemMyProgressBarControl() { RegisterMyProgressBarControl(); } public RepositoryItemMyProgressBarControl() : base() { } public override VisualBrick GetBrick(PrintCellHelperInfo info) { Bitmap bmp = new Bitmap(info.Rectangle.Width, info.Rectangle.Height); Graphics gr = Graphics.FromImage(bmp); gr.FillRectangle(new SolidBrush(Color.White), info.Rectangle); ImageBrick brick = new ImageBrick(BorderSide.None, 0, Color.Transparent, Color.Transparent); int width = Convert.ToInt32(info.Rectangle.Width * Convert.ToDouble(info.EditValue) / ((double)100)); if(width > 0) { gr.FillRectangle(new LinearGradientBrush(new Rectangle(0, 0, width, info.Rectangle.Height), Color.LightBlue, Color.White, 90, true), new Rectangle(0, 0, width, info.Rectangle.Height)); brick.Image = bmp; } gr.DrawString(info.DisplayText, info.Appearace.Font, new SolidBrush(Color.Black), new PointF(0, 0)); brick.Rect = info.Rectangle; return brick; } public static void RegisterMyProgressBarControl() { EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(MyProgressBarControlName, typeof(MyProgressBarControl), typeof(RepositoryItemMyProgressBarControl), typeof(MyProgressBarViewInfo), new ProgressBarPainter(), true)); } public override string EditorTypeName { get { return MyProgressBarControlName; } } } public class MyProgressBarViewInfo : ProgressBarViewInfo { public MyProgressBarViewInfo(RepositoryItem item) : base(item) { } } } }
WindowsApplication1/Form1.cs(vb)
C#
using System; using System.Data; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { Random random = new Random(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { gridControl1.ShowPrintPreview(); } private void Form1_Load(object sender, EventArgs e) { productsBindingSource.DataSource = GetProductsDataTable(); } DataTable GetProductsDataTable() { DataTable table = new DataTable(); table.TableName = "Products"; table.Columns.Add(new DataColumn("ProductName", typeof(string))); table.Columns.Add(new DataColumn("UnitPrice", typeof(double))); table.Columns.Add(new DataColumn("UnitsOnOrder", typeof(int))); for(int i = 0; i < 20; i++) { int index = i + 1; table.Rows.Add("Product " + index, Math.Round(random.NextDouble() * 1000, 2), random.Next(0, 9) * 10); } return table; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.