我遇到了麻烦Marquee
ProgressBar
。我需要执行一个方法 ( refreshList()
) 来获得一个List<string>
. 然后我将它分配List
给 a ComboBox
,所以ComboBox
用新的Items
. 由于refreshList()
需要 3 或 4 秒,我想运行一个Marquee
ProgressBar
. 但我做不到。ProgressBar
没问题,但ComboBox
不加载新的Items
.
我的refreshList()
方法:
private void refreshList(List<string> list)
{
albumList.DataSource = null;
albumList.DataSource = list;
}
我有以下代码,它工作正常:
private void changeDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
{
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
folderPath = "";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
folderPath = fbd.SelectedPath;
refreshList(N.getList(folderPath));
}
}
但我添加了一个ProgressBar
并编写了这段代码:
private void changeDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
{
fbd.RootFolder = Environment.SpecialFolder.MyComputer;
folderPath = "";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
folderPath = fbd.SelectedPath;
bgWorker.WorkerReportsProgress = true;
bgWorker.RunWorkerAsync();
}
}
我放置refreshList()
在doWork()
方法中:
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
refreshList(N.getList(folderPath));
}
但不幸的是,这不起作用。有人可以帮我解决这个问题吗?提前致谢。