簡體   English   中英

沒有消息框的C#數組將不會更新

[英]c# array wont update without messagebox

我有這種形式,其中包括一個組合框和一個列表框。 組合框的每個子文件夾都位於graphics文件夾內。 當組合框的選定值更改時,程序將列出選定文件夾中的每個.png文件,並將它們添加到列表框的項目中。

問題在於,在將文件添加到數組和將每個項目添加到列表框之間沒有顯示消息框的情況下,數組將保持為空。

這是代碼:

private void graphicBox_SelectedIndexChanged(object sender, EventArgs e)
{
    graphicList.Items.Clear();
    string selectedfolder = SkinSuite.Properties.Settings.Default.exepath + "\\GRAPHIC\\" + graphicBox.SelectedText;
    graphicfiles = Directory.GetFiles(SkinSuite.Properties.Settings.Default.exepath + "\\GRAPHIC\\" + graphicBox.SelectedText);
    // MessageBox.Show("FOR SOME REASON THIS DOESNT WORK IF I DONT SHOW YOU A MESSAGEBOX!");

    foreach (string file in graphicfiles)
    {
        graphicList.Items.Add(Path.GetFileName(file));
    }
}

如果我要取消注釋消息行,則代碼可以正常工作。

使用graphicBox.SelectedItem而不是graphicBox.SelectedText對我來說很好。 請像下面那樣更改代碼,也使用Path.Combine來構建文件路徑

private void graphicBox_SelectedIndexChanged(object sender, EventArgs e)
{
    graphicList.Items.Clear();
    string selectedfolder = SkinSuite.Properties.Settings.Default.exepath + "\\GRAPHIC\\" + graphicBox.SelectedItem;
    graphicfiles = Directory.GetFiles(SkinSuite.Properties.Settings.Default.exepath + "\\GRAPHIC\\" + graphicBox.SelectedText);
    // MessageBox.Show("FOR SOME REASON THIS DOESNT WORK IF I DONT SHOW YOU A MESSAGEBOX!");

    foreach (string file in graphicfiles)
    {
       graphicList.Items.Add(Path.GetFileName(file));
    }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM