c# devexpress GridContorl add progress bar

Implementation diagram of demo

Below are the steps and code

1 Define the clock event, and increase the increment of the progress bar regularly.

2: Add a progress bar

3; define the field properties

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace ProgressBar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            jindu = new JinduModel();
            jindu.jindu = 0 ;
            rarlist = new BindingList<JinduModel>();
            rarlist.Add(jindu);
            gridControl1.DataSource = rarlist;
            InitGridcontrol();
        }
        JinduModel jindu;
      //  BindingSource bs;
        BindingList<JinduModel> rarlist;
        void InitGridcontrol()
        {
             
            // new System.Timers.Timer
             // Instantiate the Timer class and set the interval to 10000 milliseconds; 
            aTimer = new System.Timers.Timer( 1000 );
             // Register the timer event 
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent );
             // Set the time interval to 2 seconds (2000 milliseconds), override the interval set by the constructor 
            aTimer.Interval = 2000 ;
             // Set whether to execute once (false) or always (true), the default is true 
            aTimer.AutoReset = true ;
             // Start timing 
            aTimer.Enabled = true ;


        }
        // Specify the event triggered by Timer 
        private   void OnTimedEvent( object source, ElapsedEventArgs e)
        {
             this.Invoke ( new Action(()=> jindu.jindu++ ));
            Console.WriteLine( " Event triggered at: {0} " , e.SignalTime);
        }
        // Timer should not be declared as a local variable, otherwise it will be recycled by GC 
        private  static System.Timers.Timer aTimer;
         private  void gridView1_CustomDrawCell( object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName == "count")
            {
                int count = 10000;//Convert.ToInt32(System.Math.Ceiling(zipfileInfo.Length / 1024.0));//datalist[0].count;//(int)this.gridView1.GetRowCellValue(e.RowHandle, "Count");
                int index = (int)e.CellValue;
                e.DisplayText = string.Format("{0}/{1}", index, count);
            }
        }

        private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column.FieldName == "count")
            {
                //   int count = (int)this.gridView1.GetRowCellValue(e.RowHandle, "count");
                //  int index = (int)e.CellValue;
                repositoryItemProgressBar1.Maximum = 10000;//Convert.ToInt32(System.Math.Ceiling(zipfileInfo.Length / 1024.0));//datalist[0].count;//count;
                e.RepositoryItem = repositoryItemProgressBar1;
            }
        }
    }
  

}
 class JinduModel : INotifyPropertyChanged
    {
        private  int _jindu;
         public  int jindu
        {
            get { return _jindu; }
            set { _jindu = value; OnPropertyChanged("jindu"); }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }
        
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324980317&siteId=291194637