c# - WPF C#:从文件 txt 为 ComboList 添加项目
问题描述
我想在 txt 文件的组合列表中插入项目。谁能帮我?我最近一直在编程,如果可能的话,我希望能得到一个简单的答案。提前致谢
解决方案
这是通过将读取文本文件的方法与添加到组合框的方法相结合,就像这段代码
// Normal way: Adding elements in the combobox
comboBox1.Items.Add(1998);
// Read a text file line by line.
string[] lines = File.ReadAllLines("C:\\Users\\Mohammad Yaser Ammar\\Desktop\\ComboList.txt"); //using System.IO;
foreach (string line in lines)
{
// Adding elements in the combobox from txt file
comboBox1.Items.Add(line);
}
祝你在 C# 的旅途上好运
推荐阅读
- mysql - 将列的聚合与同一表的另一列进行比较
- algorithm - 如何使用约束解决分配问题?
- json - Tornadofx REST 客户端
- zsh - 如何知道安装了哪个ZSH配置框架?
- python - 我什么时候可以在 PCA 之前或之后将我的数据集拆分为训练和验证集?
- angular - 总是调用 flatMap 中的第二个 API
- javascript - React setState 不像我预期的那样工作
- php - 通过 PHP 将图像从 Swift 上传到数据库
- php - 将非英文字符附加到 json 文件
- python - numpy 代码库中是否有 numpy-stubs 的替代品?