alejandro carnero
alejandro carnero

Reputation: 1784

Populate List with Directory

I use this

        if (string.IsNullOrEmpty(pastae)) { MessageBox.Show("Must choose a folder"); }
        else
        {   nombres = Directory.GetFiles(pastae).ToArray();
            listBox1.Items.AddRange(nombres);                
        }

that works fine, but i need some properties of listview , and i have read that list<> is more efficient to populate a listview in this case, i have try with this code:

      List<string> mclist = new List<string>();
      listview.Items.Clear();
      foreach(string elem in mclist)
      {
      listview.Items.Add(new ListViewItem(elem));
      }

but how i can not make this

      list<string> nmfiles = new List<string>();
      nmfiles =  Directory.GetFiles(pastae).ToArray();

Thanks by any orientation.

Upvotes: 0

Views: 104

Answers (1)

Zbigniew
Zbigniew

Reputation: 27594

You cannot assign string[] to List<string>. However you can use ToList() method to convert array into list:

List<string> nmfiles =  Directory.GetFiles(pastae).ToList();

Upvotes: 3

Related Questions