繁体   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