private void PopulateListView(string directoryPath) { if (this.listView.InvokeRequired) { this.listView.Invoke(new PopulateListViewDelegate(PopulateListView), directoryPath); } else { this.listView.Items.Clear(); if (String.IsNullOrEmpty(directoryPath)) { return; } else { List <ListViewItem> listViewItems = new List <ListViewItem>(); foreach (DirectoryInfo di in FileSystemInfoCreator.GetSubDirectoryInfoList(directoryPath)) { listViewItems.Add(ListViewItemCreator.Create(di, this.exRepListView)); } foreach (FileInfo fi in FileSystemInfoCreator.GetFileInfoList(directoryPath)) { listViewItems.Add(ListViewItemCreator.Create(fi, this.exRepListView)); } this.listView.Items.AddRange(listViewItems.ToArray <ListViewItem>()); } } }
void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e) { ListViewItem lvi = GetListViewItem(e.OldFullPath); if (lvi != null) { ListViewItemCreator.SetListViewItemValues(lvi, GetFileSystemInfo(e.FullPath), this.exRepListView); } }
private void AddItemToListView(string path) { if (this.listView.InvokeRequired) { this.listView.Invoke(new AddListViewItemDelegate(AddItemToListView), path); } else { ListViewItem lvi = ListViewItemCreator.Create(GetFileSystemInfo(path), this.exRepListView); this.listView.Items.Add(lvi); } }
void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e) { Thread.Sleep(50); // ensures all changes are properly read if (GetFileSystemInfo(e.FullPath) == null) { return; } if (e.ChangeType == WatcherChangeTypes.Changed) { ListViewItem lvi = GetListViewItem(e.FullPath); if (lvi == null) { this.AddItemToListView(e.FullPath); } else { ListViewItemCreator.SetListViewItemValues(lvi, GetFileSystemInfo(e.FullPath), this.exRepListView); } } }