![](/img/trans.png)
[英]How do you enable Code suggestion feature in C# in Visual Studio 2017?
[英]Visual Studio 2017 C# - How do you import the contents of a local .txt list into a ComboBox's options?
我需要做的就是将 .txt 文件的内容(在 VS 解决方案文件所在的同一文件夹中)导入到我在 VS 中制作的表单上的 ComboBox 选项中。 到目前为止,Google 中出现的所有内容都没有奏效。
.txt 文件中的列表项是逐行分隔的,如下所示:
asdf
sadf
sadf
asdf
asdf
不确定我是否正确回答了您的问题,但在 OnLoad 表单事件中尝试:
using System.IO;
comboBox.Items.AddRange(File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, "myFile.txt")).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.