Esempio n. 1
0
        /// <summary>
        /// Returns a sorted List<ListViewItem> with the files of received path.
        /// </summary>
        public static List <ListViewItem> GetItemsAtPath(string path, Enums.SortColumn column, Enums.SortType type)
        {
            var listViewItems = new List <ListViewItem>();
            var filesInfo     = new FileInfo[0];

            try
            {
                filesInfo = new DirectoryInfo(path).GetFiles();
            }
            catch { }

            foreach (var fileInfo in filesInfo)
            {
                var listViewItem = new ListViewItem
                {
                    Text       = fileInfo.Name,
                    ImageIndex = Constants.IMG_INDEX_FILE
                };
                listViewItem.SubItems.Add(Math.Ceiling((double)fileInfo.Length / 1024).ToString() + " KB");

                listViewItems.Add(listViewItem);
            }

            // custom sort
            listViewItems.Sort(new ColumnComparer(column, type));

            return(listViewItems);
        }
Esempio n. 2
0
        private void listViewFilePick_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            if ((int)this.sortColumn == e.Column)
            {
                this.sortType = (this.sortType == Enums.SortType.Ascending) ? Enums.SortType.Descending : Enums.SortType.Ascending;
            }
            else
            {
                this.sortColumn = (Enums.SortColumn)e.Column;
                this.sortType   = Enums.SortType.Ascending;
            }

            this.LoadFiles(this.fullPath, this.sortColumn, this.sortType);
        }
Esempio n. 3
0
        /// <summary>
        /// Load into the ListView the files that belongs to the path received
        /// A empty path string means MiComputer (default location)
        /// </summary>
        /// <param name="path">Path to load into the listview</param>
        /// <param name="column">Sorting column of the items to load into the listview</param>
        /// <param name="type">Sort order of items to load into the listview</param>
        private void LoadFiles(string path, Enums.SortColumn column, Enums.SortType type)
        {
            try
            {
                this.lblFoundFiles.Visible = false;

                List <ListViewItem> listViewItems = ListViewHelper.GetItemsAtPath(path, column, type);

                // add list to ListView control
                this.listViewFilePick.Items.Clear();
                this.listViewFilePick.Items.AddRange(listViewItems.ToArray());

                this.lblFoundFiles.Text    = listViewItems.Count.ToString() + " files found";
                this.lblFoundFiles.Visible = true;
            }
            catch (Exception) { }
        }
 public ColumnComparer(Enums.SortColumn sortColumn, Enums.SortType sortType)
 {
     this.sortColumn = sortColumn;
     this.sortType   = sortType;
 }