Popluate a ListView control with a file list

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a winforms application that is supposed to look into a specific
directory, popluate a ListView control with the contents of the directory.

I am new to this, and have not found the exact thing.

How do I populate the ListView with a given path?
 
Brian said:
I have a winforms application that is supposed to look into a specific
directory, popluate a ListView control with the contents of the directory.

I am new to this, and have not found the exact thing.

How do I populate the ListView with a given path?

void AddFiles(ListBox listBox1, string strDirectory)
{
listBox1.Items.AddRange(Directory.GetFiles(strDirectory));
}
 
Peter Duniho said:
void AddFiles(ListBox listBox1, string strDirectory)
{
listBox1.Items.AddRange(Directory.GetFiles(strDirectory));
}
I assume I need to add the path for the strDirectory variable?

public static string strDirectory;

string [] strDirectory = ("D:\");
 
Brian said:
I assume I need to add the path for the strDirectory variable?

And the "listBox1" as well. I probably should have named the parameter
something else, to make it clear that the code I posted does not
actually initialize the parameters. That's all up to you.

It is just sample code, after all. :)
 
Thanks,

Peter Duniho said:
And the "listBox1" as well. I probably should have named the parameter
something else, to make it clear that the code I posted does not
actually initialize the parameters. That's all up to you.

It is just sample code, after all. :)
 
Back
Top