Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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);
    }
  }
}


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

Bob Gatto
Posted
Updated 8-Feb-18 9:56am
v3

1 solution

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);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900