c#devexpress GridContorl添加进度条

c#devexpress GridContorl添加进度条_第1张图片

demo 的实现图

下边是步骤和代码

1定义 时钟事件,定时的增加进度条的增量.

2:  添加进度条

3;定义字段属性

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();
            rarlist.Add(jindu);
            gridControl1.DataSource = rarlist;
            InitGridcontrol();
        }
        JinduModel jindu;
      //  BindingSource bs;
        BindingList rarlist;
        void InitGridcontrol()
        {
             
            // new System.Timers.Timer
            //实例化Timer类,设置间隔时间为10000毫秒; 
            aTimer = new System.Timers.Timer(1000);
            //注册计时器的事件
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            //设置时间间隔为2秒(2000毫秒),覆盖构造函数设置的间隔
            aTimer.Interval = 2000;
            //设置是执行一次(false)还是一直执行(true),默认为true
            aTimer.AutoReset = true;
            //开始计时
            aTimer.Enabled = true;


        }
        //指定Timer触发的事件
        private  void OnTimedEvent(object source, ElapsedEventArgs e)
        {
             this.Invoke( new Action(()=> jindu.jindu++));
            Console.WriteLine("触发的事件发生在: {0}", e.SignalTime);
        }
        //Timer不要声明成局部变量,否则会被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)); }
        
    }

 

转载于:https://www.cnblogs.com/zuochanzi/p/8962263.html

你可能感兴趣的:(c#)