0

Помогите реализовать методы для перетаскивания видеофайла из проводника на форму ListView.Информация о размещении видеофайла должна отображаться в GridView ,на выделенной строке ListView в кокретном cтолбце(поле) GridView.

private void ViewAllCards_Drop(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(System.IO.Path.GetExtension(s), ".avi", true) == 0)
                    {
                        AddFileToViewAllCards(s);
                    }
                if (string.Compare(System.IO.Path.GetExtension(s), ".mkv", true) == 0)
                {
                    AddFileToViewAllCards(s);
                }

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

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

            }

            else if (Directory.Exists(s))
            {
                DirectoryInfo di = new DirectoryInfo(s);
                FileInfo[] files = di.GetFiles("*.avi");
                foreach (FileInfo file in files)
                AddFileToViewAllCards(file.FullName);

            }
        }
    }


    public void AddFileToViewAllCards(string fullFilePath)
    {

        string fileName = System.IO.Path.GetFileName(fullFilePath);
        string dirName = System.IO.Path.GetDirectoryName(fullFilePath);
        if (dirName.EndsWith(Convert.ToString(System.IO.Path.DirectorySeparatorChar)))
        dirName = dirName.Substring(0, dirName.Length - 1);
        ViewAllCards.ItemsSource = null;

        ViewAllCards.Items.Clear();

        ViewAllCards.Items.Add(fileName);



    }
    private void ViewAllCards_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
        {
            e.Effects = DragDropEffects.Copy;
        }
        else 
            e.Effects = DragDropEffects.None;
    }

Ничего не происходит, данные в ListView не отображаются

aepot
  • 49,560
  • Что именно не получается? https://stackoverflow.com/a/5663329/12888024 – aepot Nov 01 '22 at 21:04
  • ViewAllCards.Items.Clear(); так вы при добавлении каждого очищаете список. И вообще познакомьтесь с привязками данных и ObservableCollection. А в handles что приходит? – aepot Nov 01 '22 at 22:05
  • Я пытаюсь закинуть на форму видео файл .avi из проводника – Дмитрий Nov 02 '22 at 08:32
  • Не понятно как обозначить цель куда мой файл должен распарситься(конкретное поле в List View) – Дмитрий Nov 02 '22 at 08:35
  • <ListView.ItemTemplate> https://ru.stackoverflow.com/a/1116136/373567 или GridView с биндингами, я не знаю, что там у вас на самом деле. – aepot Nov 02 '22 at 09:38

0 Answers0