Beispiel #1
0
        private void ListView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var  listView            = (ListView)sender;
            bool isLeftPanel         = listView.Name == "listViewLeft";
            ListViewHitTestInfo info = listView.HitTest(e.X, e.Y);
            CustomListViewItem  item = (CustomListViewItem)info.Item;

            if (item != null && item.Type == CustomListViewItemTypeEnum.Directory || item.Type == CustomListViewItemTypeEnum.RemoteDirectory)
            {
                RefreshListView(isLeftPanel, item.FullPath);
            }
            else
            {
                try
                {
                    Process proc = new Process();
                    proc.StartInfo.FileName        = item.FileInfo.FullName;
                    proc.StartInfo.UseShellExecute = true;
                    proc.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #2
0
        private CustomListViewItem CreateListViewItem(CustomListViewItemTypeEnum itemType, DirectoryInfo dirInfo, FileInfo fInfo)
        {
            bool   isDir          = itemType != CustomListViewItemTypeEnum.File;
            string name           = string.Empty;
            string lastAccessTime = string.Empty;

            switch (itemType)
            {
            case CustomListViewItemTypeEnum.Directory:
                name           = dirInfo.Name;
                lastAccessTime = dirInfo.LastAccessTime.ToShortDateString();
                break;

            case CustomListViewItemTypeEnum.File:
                name           = fInfo.Name;
                lastAccessTime = fInfo.LastAccessTime.ToShortDateString();
                break;

            case CustomListViewItemTypeEnum.RemoteDirectory:
                name = "\\\\" + dirInfo.Name;
                break;

            default:
                name = string.Empty;
                break;
            }

            var item = new CustomListViewItem(name, (int)itemType);

            item.DirectoryInfo = dirInfo;
            item.FileInfo      = fInfo;
            item.Type          = itemType;

            var subItems = new ListViewItem.ListViewSubItem[]
            {
                new ListViewItem.ListViewSubItem(item, itemType.ToString()),
                new ListViewItem.ListViewSubItem(item, lastAccessTime)
            };

            item.SubItems.AddRange(subItems);
            return(item);
        }
Beispiel #3
0
        private void ListFiles(ListView listView, DirectoryInfo dirInfo, bool listRoot = false)
        {
            CustomListViewItem item = null;

            if (listRoot)
            {
                item = CreateListViewItem(CustomListViewItemTypeEnum.Directory, dirInfo, null);
                listView.Items.Add(item);
            }
            else
            {
                foreach (DirectoryInfo dir in dirInfo.GetDirectories())
                {
                    item = CreateListViewItem(CustomListViewItemTypeEnum.Directory, dir, null);
                    listView.Items.Add(item);
                }

                foreach (FileInfo file in dirInfo.GetFiles())
                {
                    item = CreateListViewItem(CustomListViewItemTypeEnum.File, null, file);
                    listView.Items.Add(item);
                }
            }
        }