如何在GridView中删除重复数据

时间:2019-05-21 06:17:56

标签: c# file gridview uwp

我有一个GridView,用于显示本地文件夹中的数据。如果数据在本地文件夹中尚不存在,我希望它从解决方案包中的“ uu文件”中复制。而如果它已经在本地文件夹中,它将立即从本地文件夹中获取数据。

代码:

ObservableCollection<Book> datasource = new ObservableCollection<Book>();    
StorageFolder _folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    _folder = await _folder.GetFolderAsync("UU pdf");
    _folder = await _folder.GetFolderAsync(direktori.Direktori);
    _folder = await _folder.GetFolderAsync(direktori.Name);
    IReadOnlyList<StorageFile> _files = await _folder.GetFilesAsync(); //which returns List<StorageFile>

    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
    StorageFolder localFolder1 = await localFolder.CreateFolderAsync("FileUU", CreationCollisionOption.OpenIfExists);
    ((App)(App.Current)).DirectoriName = direktori.Direktori;
    StorageFolder localFolder2 = await localFolder1.CreateFolderAsync(((App)(App.Current)).DirectoriName, CreationCollisionOption.OpenIfExists);
    ((App)(App.Current)).DirektoriYear = direktori.Name;
    StorageFolder localFolder3 = await localFolder2.CreateFolderAsync(((App)(App.Current)).DirektoriYear, CreationCollisionOption.OpenIfExists);
    foreach (StorageFile file in _files)
    {
        if (!CheckFileExists(file.Name))    
        {
            try
            {
                        await file.CopyAsync(localFolder3);
                }
                catch
            {
            }
        }
    }
    IReadOnlyList<StorageFile> _filesC = await localFolder3.GetFilesAsync();
    foreach (StorageFile fileC in _filesC)
    {
        string name = @"SELECT filename from undangundang where identifier='" + fileC.DisplayName.Replace("_", " ").ToUpper() + "'";
            var nameQuery = objConnUpdate.Prepare(name);
            nameQuery.Step();
            Book buku = new Book();
            string name1 = nameQuery[0].ToString().Replace("_", " ");
            buku.Name = name1;
            datasource.Add(buku);
    }
    itemGridView.ItemsSource = datasource;

Book.cs

public class Book
    {
        public string Name { get; set; }

        public string Direktori { get; set; }

        public ImageSource Image { get; set; }
    }

我有一个问题,那就是在GridView中显示的数据总是重复如下所示: duplicate data on gridview

我该如何处理?

0 个答案:

没有答案