首页 > 解决方案 > WPF C#:从文件 txt 为 ComboList 添加项目

问题描述

我想在 txt 文件的组合列表中插入项目。谁能帮我?我最近一直在编程,如果可能的话,我希望能得到一个简单的答案。提前致谢

标签: c#

解决方案


这是通过将读取文本文件的方法与添加到组合框的方法相结合,就像这段代码

        // 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# 的旅途上好运


推荐阅读