我想對文件夾中的文件做一個列表視圖,但它不起作用。這段代碼有什麼問題?文件在列表視圖中的文件
DialogResult wczytywanie_z_folderu = new DialogResult();
wczytywanie_z_folderu = folderBrowserDialog1.ShowDialog();
string[] pliki_w_folderze = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
if (wczytywanie_z_folderu == DialogResult.OK)
{
List<string> lista = new List<string>();
lista = pliki_w_folderze.ToList();
int dl_listy = lista.Count;
int dlugosc = pliki_w_folderze.Length;
for (int i = 0; i == dlugosc; i = i + 1)
{
string alfabet = "abcdefghijklmnopqrstuwvxyz";
char[] litery = alfabet.ToCharArray();
Random r = new Random();
string temp = "";
for (int j = 0; j < 1; j++)
{
int random_letter = r.Next(litery.Length);
temp += litery[random_letter].ToString();
ListViewItem str = new ListViewItem(temp);
str.Text = lista[i];
listView1.Items.Add(str);
}
}
與您的問題無關:第一行('DialogResult wczytywanie_z_folderu = new DialogResult();')是多餘的。刪除它,只需寫入'DialogResult wczytywanie_z_folderu = folderBrowserDialog1.ShowDialog();'。這同樣適用於'新列表',它也是多餘的。 –
Timwi
2010-09-06 00:14:34