我有一個應用程序,檢查一些7zip arhive,如果他們沒有損壞,並且我想寫一個列表框中的每個動作,但我的問題是,列表框不顯示每行時添加項目到它,它在更新完成,並把所有的項目在我的結束動作,即使我使用屬性.StartUpdate()和EndUpdate()立即更新列表框
這是我的代碼的一部分:
foreach (string director in foldere)
{
if (director.ToLower().Contains("cluj") || director.ToLower().Contains("craiova") || director.ToLower().Contains("timisoara"))
{
String[] zipFile = Directory.GetFiles(director, "*.7z");
foreach (string zip7 in zipFile)
{
//check arhive
SevenZipExtractor zipfile = new SevenZipExtractor(zip7);
if (zipfile.Check())
{
String[] fisFaraArhiva = Directory.GetFiles(director, "*.*");
foreach (string fisere in fisFaraArhiva)
{
if (fisere != zip7)
{
File.Delete(fisere);
}
}
listBox1.Items.Insert(0, "A fost sters fisierele din directorul " + director);
string[] fisComanda = Directory.GetFiles(utilizator, "*" + id + "*");
foreach (string cmd in fisComanda)
{
File.Move(cmd, Path.Combine(director, Path.GetFileName(cmd)));
listBox1.BeginUpdate();
listBox1.Items.Insert(0, "A fost mutata comanda " + Path.GetFileName(cmd) + " in director");
listBox1.EndUpdate();
}
}
else
{
MessageBox.Show("Arhiva nu este ok");
listBox1.BeginUpdate();
listBox1.Items.Insert(0, "Arhiva " + zip7 + " NU este OK");
listBox1.BackColor = Color.Red;
listBox1.EndUpdate();
}
}
}
}
if (listBox1.BackColor != Color.Red)
{
listBox1.BeginUpdate();
listBox1.BackColor = Color.Green;
listBox1.EndUpdate();
}
thaks非常非常的多! – XandrUu