Tôi là người mới trong C# và tôi có 2 Hộp danh sách l -> istBox1 và listBox2 và tôi muốn tải tệp từ thư mục vào các hộp danh sách này. tôi đã cố gắng như thế này: listBox1:
Điền các tệp vào hộp danh sách từ thư mục trong các cửa sổ C#
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestLoadFiles");
FileInfo[] Files = dinfo.GetFiles("*.rtdl");
foreach (FileInfo file in Files)
{
listbox1.Items.Add(file.Name);
}
}
listBox2:
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestLoadFiles");
FileInfo[] Files = dinfo.GetFiles("*.dlz");
foreach (FileInfo file in Files)
{
listbox2.Items.Add(file.Name);
}
}
khi tôi chạy theo hình thức, các tập tin từ thư mục không hiển thị ???
Tốt. và bây giờ câu hỏi của bạn là gì? – Reniuz
sự cố là gì? trong selectindexchanged xử lý cho listbox1, bạn lại một lần nữa populating listbox1 – rt2800
bạn đã làm nó, thực sự ... – Tigran