将数据源分配给XtraTreeList时的进度

时间:2016-07-17 19:14:57

标签: treeview devexpress

我有一个XtraTreeList,我为它分配了一个巨大的数据源(包含数百万个项目)

xtraTree.TreeViewData = dataSource;

此操作需要80秒才能完成,考虑到节点数量,这完全没问题。

我只想向用户显示一个可靠的进度条,指示已处理了多少个节点。

我试过了:

  • 查看活动列表,但我只找到PrintExportProgress
  • 搜索主题,希望我能在DevExpress支持页面上找到一些东西

如果重要的话,我正在使用WinForms版本15.2版。

这不是关于在构建数据源时显示进度。有两个步骤:

  • 构建数据源(从文件中读取) - 这也需要60秒,但我自己这样做,我在这里没有问题
  • 将数据源分配给XtraTreeList - 有效,但我没有得到进度信息,需要在UI线程上完成,这是阻塞

这也与进度条的跨线程更新无关。我知道该怎么做。

1 个答案:

答案 0 :(得分:-1)

嘿,我在使用WinForms构建的项目中做了同样的事情...除了我只有4500项 - 这些项目是我必须从中提取数据的文件。我所做的是在我处理的每个文件中(在我的foreach循环的底部)我调用了一个方法来更新我的表单上的进度条:

Form1.UpdateProgressbar();

在我的Form1.cs中,我这样做了:

public void UpdateProgressbar()
    {

        progressBar2.Increment(1);
        label7.Text = "Processed: " + Convert.ToString(progressBar2.Value) + " out of " + Globals.totalartistcount + " Artists";
        label8.Text = "Processed: " + Globals.songcounter + " Songs.      Processing: " + Globals.artist;
        label9.Text = "Total Number of Songs to process: " + Globals.totalsongcount;

        progressBar2.Update();
        Application.DoEvents();
    }

如果我没记错的话

Application.DoEvents();

对于实际看到进度条移动以及标签更新其文本至关重要。我用这种方式初始化了我的进度条:

       /* ------ progress bar ------------------------------------------ */

    public void InitializeProgressBar(DirectoryInfo di)
    {
        int songcount = 0;
        int artistcount = 0;
        int index = 0;



        //Get Total number of folders
        foreach (var sf in di.GetDirectories())
        {
            //find index of artist to process
            //this is just an array of artist names and if true or false to process
            for (int i = 0; i <= Globals.artists.GetUpperBound(0); i++)
            {
                if (sf.Name == Globals.artists[i, 0])
                {
                    index = i;
                    break;
                }
            }

            if (Globals.artists[index, 1] != "false")
            {
                // Get a total number of files to process (MAX)
                foreach (var fi in sf.GetFiles("*.mp3"))
                {
                    songcount++;
                }
                artistcount++;

            }
        }

        Globals.totalartistcount = artistcount;
        Globals.totalsongcount = songcount;
        progressBar2.Minimum = 0;
        progressBar2.Maximum = artistcount - 1;
        progressBar2.Value = 0;
        Application.DoEvents();
    }

在那里,我希望有所帮助。

相关问题