private void SetupList() { // We want to draw the system icon against each file name. SysImageListHelper does this work for us. SysImageListHelper helper = new SysImageListHelper(this.olvFiles); this.olvColumnName.ImageGetter = delegate(object x) { return(helper.GetImageIndex(((FileSystemInfo)x).FullName)); }; // Show tooltips when the appropriate checkbox is clicked this.olvFiles.ShowItemToolTips = true; this.olvFiles.CellToolTipShowing += delegate(object sender, ToolTipShowingEventArgs e) { if (this.showToolTipsOnFiles) { e.Text = String.Format("Tool tip for '{0}', column '{1}'\r\nValue shown: '{2}'", e.Model, e.Column.Text, e.SubItem.Text); } }; // Show a menu -- but only when the user right clicks on the first column this.olvFiles.CellRightClick += delegate(object sender, CellRightClickEventArgs e) { System.Diagnostics.Trace.WriteLine(String.Format("right clicked {0}, {1}). model {2}", e.RowIndex, e.ColumnIndex, e.Model)); if (e.ColumnIndex == 0) { e.MenuStrip = this.contextMenuStrip2; } }; }
public ImportSourceFileBrowser() { InitializeComponent(); sysImgHelper = new SysImageListHelper(this.olvFiles); this.olvFilesCustomize(); }
private void SetupColumns() { // The column setup here is identical to the File Explorer example tab -- // nothing specific to the TreeListView. // The only difference is that we don't setup anything to do with grouping, // since TreeListViews can't show groups. SysImageListHelper helper = new SysImageListHelper(this.treeListView); this.olvColumnName.ImageGetter = delegate(object x) { return(helper.GetImageIndex(((MyFileSystemInfo)x).FullName)); }; // Get the size of the file system entity. // Folders and errors are represented as negative numbers this.olvColumnSize.AspectGetter = delegate(object x) { MyFileSystemInfo myFileSystemInfo = (MyFileSystemInfo)x; if (myFileSystemInfo.IsDirectory) { return((long)-1); } try { return(myFileSystemInfo.Length); } catch (System.IO.FileNotFoundException) { // Mono 1.2.6 throws this for hidden files return((long)-2); } }; // Show the size of files as GB, MB and KBs. By returning the actual // size in the AspectGetter, and doing the conversion in the // AspectToStringConverter, sorting on this column will work off the // actual sizes, rather than the formatted string. this.olvColumnSize.AspectToStringConverter = delegate(object x) { long sizeInBytes = (long)x; if (sizeInBytes < 0) // folder or error { return(""); } return(Coordinator.FormatFileSize(sizeInBytes)); }; // Show the system description for this object this.olvColumnFileType.AspectGetter = delegate(object x) { return(ShellUtilities.GetFileType(((MyFileSystemInfo)x).FullName)); }; // Show the file attributes for this object // A FlagRenderer masks off various values and draws zero or images based // on the presence of individual bits. this.olvColumnAttributes.AspectGetter = delegate(object x) { return(((MyFileSystemInfo)x).Attributes); }; FlagRenderer attributesRenderer = new FlagRenderer(); attributesRenderer.ImageList = imageListSmall; attributesRenderer.Add(FileAttributes.Archive, "archive"); attributesRenderer.Add(FileAttributes.ReadOnly, "readonly"); attributesRenderer.Add(FileAttributes.System, "system"); attributesRenderer.Add(FileAttributes.Hidden, "hidden"); attributesRenderer.Add(FileAttributes.Temporary, "temporary"); this.olvColumnAttributes.Renderer = attributesRenderer; // Tell the filtering subsystem that the attributes column is a collection of flags this.olvColumnAttributes.ClusteringStrategy = new FlagClusteringStrategy(typeof(FileAttributes)); }