I mam having problems doing somthing fairly simple. ;) . What i have is a listview with about 1000 items in it. All files paths that i have scanned from a directory. And there are 4 colums. First the name, then the size, extesion ect. the last is the path to the file. Right now the user can click to copy them and they are all copied to a differ location. Thats easy....they can also choose to just copy the one checked one. Thats easy to i used this

try
            {
                string s = Registry.CurrentUser.OpenSubKey(@"Software\ManagePod\GeneralConfig", true).GetValue("CopyDir").ToString();   
                string mp3 = listViewFiles.SelectedItems[0].SubItems[3].Text.ToString();
                MP3File mp3File = ShellID3TagReader.ReadID3Tags(mp3);
                File.Copy(mp3, s + "\\" + mp3File.SongTitle + "-" + mp3File.ArtistName + ".mp3");
            }
            catch
            {

                //error handling
            }

Now what i want to be able to do is let the user copy any files that are Checked.. So say they check off six files. On a button click i want the six checked files copied to the target location. Now i no this should be easy. But i am strugling witht the subitems part. I have somthing like this.

//so here is some puesdo code
foreach(4th column of every checked item)//the 4th column is that path
{
File.Copy(the path of each 4th selected item, target loaction
}

Thanks for any help

-T

foreach (ListViewItem lvi in this.listViewFiles.CheckedItems)
			{
// do whatever here
				string s =  lvi.SubItems[3];
			}
foreach (ListViewItem lvi in this.listViewFiles.CheckedItems)
			{
// do whatever here
				string s =  lvi.SubItems[3];
			}

Thanks. But i hd tried somthing similar to that and it failed. So did yours. See when i do the copy functin it says that path is not supported. so using this code

foreach (ListViewItem lvi in this.listViewFiles.CheckedItems)
            {
                string s = lvi.SubItems[3].ToString();
                MessageBox.Show(s);       
            }

I had a messagebox show me it, it looks like this

ListViewItem: {thepath}

thats not going to work. Any ideas?

btw this is the code i tried to use to copy it. but because of the format it didnt work.

string s1 = Registry.CurrentUser.OpenSubKey(@"Software\ManagePod\GeneralConfig", true).GetValue("CopyDir").ToString();   //this is an entry in th e reg it is the path to a dir. this case the dir where it will be copied to.
            foreach (ListViewItem lvi in this.listViewFiles.CheckedItems)
            {
                string s = lvi.SubItems[3].ToString();
                MP3File mp3File = ShellID3TagReader.ReadID3Tags(s);//class to read MP3's
                File.Copy(s, s1 + "\\" +  mp3File.SongTitle + "-" + mp3File.ArtistName + ".mp3");
                
            }

-T

lvi.SubItems[3].Text

Thanks that did it :)

-T

P.s that was easy :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.