如何从openfile对话框中将项目添加到listviw? [英] How do I add items to a listviw from an openfiledialog?

查看:90
本文介绍了如何从openfile对话框中将项目添加到listviw?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试显示用户选择的所有选定文件.但是在我运行程序之后,单击按钮,并进行选择,ListVie仍然显示为空.
我使用的代码是这样的:

我尝试过的事情:

Hello,

I''m trying to display all of the selected files a user selects. But after I run the program, click the button, and make the selections the ListVie still comes up empty.
The code I used is this:

What I have tried:

private void button1_Click(object sender, EventArgs e)
{
  using(OpenFileDialog fle = new OpenFileDialog())
  {
    fle.Filter = "Text, PHP, and Javascript (*.txt, *.php, *.js) | *.txt; *.php; *.js | PHP (*.php) | *.php | Text (*.txt) | *.txt | Javascript (*.js) | *.js | All files(*.*) | *.*";
    fle.Multiselect = true;
    DialogResult answer = fle.ShowDialog();
    if (answer == DialogResult.OK)
    {
      listView1.Clear();
      ListViewItem lvi = new ListViewItem(fle.FileNames);
      listView1.Items.Add(lvi);
    }
  }
}



为什么ListView没有填满?
感谢您的帮助,

Bob Gatto



Why is the ListView not filling up?
Thanks for the help,

Bob Gatto

推荐答案

您的代码几乎可以,请尝试以下操作:
Your code is almost ok, try this:
listView1.View = View.List;
listView1.Clear();

foreach (var item in fle.FileNames)
{
    ListViewItem lvi = new ListViewItem(item);
    listView1.Items.Add(lvi);
}


这篇关于如何从openfile对话框中将项目添加到listviw?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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