How to access/select all the listViewSubItems when a listViewItem is clicked?

18 Views Asked by At

If I select a listViewItem (eg.imgs) , I want to access all the files in the directory and download them.

The treeView and listView contextMenuStrip

This is the code I have. When I click on the directory and press the download, the directory is not downloaded. But this code works fine for downloading individual files.

        private async void DownloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "Download ";
            var sfd = new FolderBrowserDialog();
            sfd.SelectedPath = Settings.GetUserDataDirectory();
            var dr = sfd.ShowDialog();
            foreach (ListViewItem listView1SelectedItem in listView1.SelectedItems)
            {
                toolStripStatusLabel1.Text = "Download " + listView1SelectedItem.Text;
                if (dr == DialogResult.OK)
                {
                    var path = treeView1.SelectedNode.FullPath + "/" + listView1SelectedItem.Text;
                    ProgressReporterDialogue prd = new ProgressReporterDialogue();
                    CancellationTokenSource cancel = new CancellationTokenSource();
                    prd.doWorkArgs.CancelRequestChanged += (o, args) =>
                    {
                        prd.doWorkArgs.ErrorMessage = "User Cancel";
                        cancel.Cancel();
                        _mavftp.kCmdResetSessions();
                    };
                    prd.doWorkArgs.ForceExit = false;
                    Action<string, int> progress = delegate (string message, int i)
                    {
                        prd.UpdateProgressAndStatus(i, toolStripStatusLabel1.Text);
                    };
                    _mavftp.Progress += progress;

                    prd.DoWork += (iprd) =>
                    {
                        var ms = _mavftp.GetFile(path, cancel, false);
                        if (cancel.IsCancellationRequested)
                        {
                            iprd.doWorkArgs.CancelAcknowledged = true;
                            iprd.doWorkArgs.CancelRequested = true;
                            return;
                        }

                        var file = Path.Combine(sfd.SelectedPath, listView1SelectedItem.Text);
                        int a = 0;
                        while (File.Exists(file))
                        {
                            file = Path.Combine(sfd.SelectedPath, listView1SelectedItem.Text) + a++;
                        }
                        File.WriteAllBytes(file, ms.ToArray());
                    };
                    prd.RunBackgroundOperationAsync();
                    _mavftp.Progress -= progress;
                }
                else if (dr == DialogResult.Cancel)
                {
                    return;
                }
            }

            toolStripStatusLabel1.Text = "Ready";
        }

0

There are 0 best solutions below