自动填写下拉菜单 [英] Automatic fill in of a drop down menu

查看:96
本文介绍了自动填写下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让下拉菜单自动读取指定文件夹中的所有文本文件并将其显示在下拉菜单中?

因为现在我正在编写txt文件一个接一个地将它们一个接一个地连接到正确的按钮。

但是有没有办法让下拉菜单自动加载它们?

Is there a way that a drop down menu can automaticly read all the text files in a specified folder and display them into the drop down menu?
Because now I''m actually programming the txt files one by one and coupling them one by one to the correct buttons.
But is there a way that the drop down menu can load them in automatic?

推荐答案

试试这个



Try this

System.IO.DirectoryInfo x = new System.IO.DirectoryInfo("c:\\");
this.comboBox1.DataSource = x.GetFiles();


1。您可以使用FileInfo和DirectoryInfo类来获取文件列表(如果您愿意,可以在txt扩展名上进行过滤)。 2. 2.使用该阵列,您可以填写下拉菜单。

3.单击菜单项时,使用选定的文件名打开该文件,例如StreamReader类。



这假设您已将root文件夹设置为配置。



希望这会有所帮助。
1. You can use the the FileInfo and DirectoryInfo classes to get the list of files (filtered on txt extension if you wish). 2. 2. With that array you can fill your drop down menu.
3. When you click the menu item, open that file with the selected filename with for example the StreamReader class.

This is assuming that you have set a rootfolder as config.

Hope this helps.


这篇关于自动填写下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆