嗨,列表框问题. [英] Hi listbox problem....

查看:54
本文介绍了嗨,列表框问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在名为data.txt的文件中有一个数据,它们看起来像是e.x:

葡萄牙ronado [3]
阿根廷梅西[4]
梅苏厄齐尔德国[5]

现在,我想使用Windows应用程序调用此文件,然后将这些数据放入列表框...我正在使用这种代码:

Hi,

I have a data in a file called data.txt they look like that e.x:

ronado portugal [3]
mesi argentina [4]
mesu ozil germany [5]

Now I want to call this file with windows app and then those data to put in a Listbox... I am using this kind of code:

OpenFileDialog dialogu = new OpenFileDialog();
            dialogu.Filter = "*.txt|*.txt";
            if (dialogu.ShowDialog() == DialogResult.OK)
            {
                listBox1.DataSource = File.ReadAllText(dialogu.FileName, System.Text.Encoding.Default);
                
            }





it doesn''t work !!!

推荐答案

尝试:
listBox1.DataSource = File.ReadAllLines(dialogu.FileName, System.Text.Encoding.Default);


您好
检查此
Hi
Check this
private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog dialogu = new OpenFileDialog();
    dialogu.Filter = "*.txt|*.txt";
    if (dialogu.ShowDialog() == DialogResult.OK)
    {
        string[] all = File.ReadAllLines(dialogu.FileName, System.Text.Encoding.Default);
        listBox1.DataSource = all;

    }
}



最好的问候
M.Mitwalli



Best Regards
M.Mitwalli


您需要使用Itemsource进行列表框控制.数据源在WPF中不起作用

You need to use Itemsource for List box control. Datasource will not work in WPF

lstBox.ItemsSource = System.IO.File.ReadAllLines(dialogu.FileName, System.Text.Encoding.Default);


这篇关于嗨,列表框问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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