C#如何从txt文件中获取combobox.item.add字符串? [英] C# how make combobox.item.add strings from txt file resouces ?

查看:74
本文介绍了C#如何从txt文件中获取combobox.item.add字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。需要帮忙。我有一个文本文件,我想使用写作的例子

1

2

3

4

5

6



并将这些行添加到组合框中,但我正在做的方式它只出现在文本文件的第一行。其他人没有。我能做什么?谢谢。



Hello guys. Need help. I have a text file which I want to use the lines of writing example
1
2
3
4
5
6

And add those lines to the combobox, but the way I'm doing it only appears the first line of the text file. The others do not. What can I do? Thank you.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;

namespace Trainer_C3
{
    static class ContentLoading
    {
        public static string GetXmlContent()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            const string NAME = "Trainer_C3.x86x64.txt";
            using (Stream stream = assembly.GetManifestResourceStream(NAME))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();


                }
            }
        }
    }
}





使用电话





using call

public Form1()
       {
           InitializeComponent();

           comboBox2.Items.Add ( ContentLoading.GetXmlContent());

       }





我的尝试:



我需要它来显示组合框中的所有行,但它只显示最后一行



What I have tried:

I need it to show all the lines in the combobox, but it only shows the last one

推荐答案

ComboBox.ObjectCollection.AddRange Method( Object [])(System.Windows.Forms) [ ^ ]。


完成。 =)



Complete. =)

StringReader txt = new StringReader(Trainer_C3.Properties.Resources.x86x64);
            string data;
            data = txt.ReadToEnd();           
            string x = data;
            string[] y = x.Split('\n');
            foreach (string s in y)
            comboBox2.Items.Add(s);


这篇关于C#如何从txt文件中获取combobox.item.add字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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