views:

241

answers:

4

Hi, do you know any good example how to create listView which will look and has the same methods as windows explorer.

copying, pasting, display thumbnails ??

I must use listView because I can't allow user to change directory, and I can't disable this option in windows explorer(I mean the place where can I click to go up or down or put path.

+1  A: 

It's no trivial task, but you can have a look at this project. It's in VB.Net but it might serve as a source of inspiration.

klausbyskov
+1  A: 

I wrote something, but I don't know how to add event on click on icon to get path of this icon.

    path = folderBrowserDialog1.SelectedPath;


ImageList imageList1 = new ImageList();
imageList1.ImageSize = new Size(256, 256);
imageList1.ColorDepth = ColorDepth.Depth24Bit;
string[] iconFiles = Directory.GetFiles(path, "*.jpg");

foreach (string iconFile in iconFiles)
{
   try
   {
      imageList1.Images.Add(Image.FromFile(iconFile));
   }
   catch
   {
         MessageBox("Error","");
   }
}

this.listView1.View = View.LargeIcon;
this.listView1.LargeImageList = imageList1;

for (int j = 0; j < imageList1.Images.Count; j++)
{
    ListViewItem item = new ListViewItem();

    item.ImageIndex = j;   
    this.listView1.Items.Add(item);               
}

How to rebuild this code ??

A: 

You can use Graphics.DrawImage to load the jog file and create a thumbnail out of it. This will only work for image files.

To get thumbnails of other file types, you must use the shell IExtractIcon interface.

For copying/pasting, use the DataFormats.FileDrop format with full paths of the files.


For a ready-made alternative, see our FileView control.

logicnp
+1  A: 

I've been recommending this project, never heard a complaint about it. Note that an embeddable browser is available since Vista, it is wrapped by the ExplorerBrowser class available in the Windows API Code Pack.

Beware that these kind of solutions put a lot of dependencies into your project. Consider weighing that cost against simply implementing the OpenFileDialog's FileOk event and canceling the OK button click if you don't like the path.

Hans Passant