i want to do in my program that i can drag and drop any video file and it will drag their's name one after one in the first column
and when i will drag srt files (subtitles files) it will drag and drop them one after one to the other column (the other column it's actually the subitem of the video files)

so.. i succeeded with the drag and drop of the videos
but i don't know how to drag and drop the subTitles files into the next row as subitems of the videos files

Recommended Answers

All 7 Replies

I dont really get yout question. Is it that you cant retreive the stirng of the subitem (the path of the subtitle)?
To get subitem you do:

string path = listView.SelectedItems[0].SubItems[1].Text;

ok this is the code:
now the video file works great (the drag and drop) but i want that when i drag .srt files (subTitles) it will drop them in Column2

private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy;
        }
        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            string[] handles = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            foreach (string s in handles)
            {
                if (File.Exists(s))
                {
                    if (string.Compare(Path.GetExtension(s), ".avi", true) == 0)
                    {
                        AddFileToListview1(s);
                    }

                    if (string.Compare(Path.GetExtension(s), ".mkv", true) == 0)
                    {
                        AddFileToListview1(s);
                    }

                    if (string.Compare(Path.GetExtension(s), ".mp4", true) == 0)
                    {
                        AddFileToListview1(s);
                    }

                    if (string.Compare(Path.GetExtension(s), ".wtv", true) == 0)
                    {
                        AddFileToListview1(s);
                    }


                    if (string.Compare(Path.GetExtension(s), ".srt", true) == 0)
                    {
                        AddFileToListviewSRT(s);
                    }
                }
                else if (Directory.Exists(s))
                {
                    DirectoryInfo di = new DirectoryInfo(s);
                    FileInfo[] files = di.GetFiles("*.avi");
                    foreach (FileInfo file in files)
                        AddFileToListview1(file.FullName);

                    DirectoryInfo diSRT = new DirectoryInfo(s);
                    FileInfo[] filesSRT = di.GetFiles("*.srt");
                    foreach (FileInfo file in files)
                        AddFileToListviewSRT(file.FullName);
                }
            }
        }

        ListViewItem itm = new ListViewItem();
        public void AddFileToListview1(string fullFilePath)
        {
            //if (!File.Exists(fullFilePath))
            //    return;
            string fileName = Path.GetFileName(fullFilePath);
            string dirName = Path.GetDirectoryName(fullFilePath);
            if (dirName.EndsWith(Convert.ToString(Path.DirectorySeparatorChar)))
                dirName = dirName.Substring(0, dirName.Length - 1);
            ////hack off the trailing \      
            itm = listView1.Items.Add(fileName);
            itm.SubItems.Add(dirName);
            ////second column = path   
        }

        public void AddFileToListviewSRT(string fullFilePath)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                string fileName = Path.GetFileName(fullFilePath);
                string dirName = Path.GetDirectoryName(fullFilePath);
                if (dirName.EndsWith(Convert.ToString(Path.DirectorySeparatorChar)))
                    dirName = dirName.Substring(0, dirName.Length - 1);

                listView1.Items[0].SubItems[2].Text = fileName;
                listView1.Items[0].SubItems[3].Text = fileName;
                listView1.Items[0].SubItems[4].Text = dirName;
            }
        }

In your method "ADdFileToListViewSRT" you have to change the code of Items[xx] - where xx is i!

//in the for loop:
listView1.Items[i].SubItems[2].Text = fileName;
//do the same for all 3 (change with the i variable).

ohh opps, i did that at first it want work, so i changed it to [0] to check
hh but also with it doesn't work i just forgot to change back to

ohh opps, i did that at first it wasn't work, so i changed it to [0] to check
hh but also with it doesn't work i just forgot to change back to

(i did a writing mistake)

please someone help

in your code you suppose to execute line number 78 to line number 80 if if-condition is true? if yes then where are the access specifiers?

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.