我只是想遷移一些我從贏-形式WPF老的應用程序。在我以前的雙贏形式的應用程序中,我可以使用下面的代碼將數組發送到ListBox
。如何將數組發送到列表框?
在我的新WPF應用程序,這將不填充ListBox
。奇怪的是它沒有出錯,它只是不起作用。
...好它沒有錯誤的我第一次測試,我得到一個消息,說我沒有權限的應用程序,但現在它只是顯示消息說「做」而不做任何事情。
private void btnFolderBrowser_Click(object sender, RoutedEventArgs e)
{
getFileStructure();
System.Windows.Forms.MessageBox.Show("done!");
}
private void getFileStructure()
{
string myDir = "";
int i;
string filter = txtFilter.Text;
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.Desktop;
fbd.ShowNewFolderButton = false;
fbd.Description = "Browse to the root directory where the files are stored.";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
myDir = fbd.SelectedPath;
try
{
txtRootDir.Text = fbd.SelectedPath;
string[] fileName = Directory.GetFiles(myDir, filter, SearchOption.AllDirectories);
for (i = 0; i < fileName.Length; i++)
lstFileNames.Items.Add(fileName[i]);
}
catch (System.Exception excep)
{
System.Windows.Forms.MessageBox.Show(excep.Message);
return;
}
}
你嘗試把一個斷點,以確保實際上正在填充列表? – Blachshma
那麼有沒有什麼文件名?,PS沒有很好的命名,這是它... –
你是什麼意思,沒有很好的名字?對不起,如果這是一個愚蠢的問題,我不是一個開發人員,但我想知道適當的標準。 – bolilloBorracho