explorer – Owl's Blog on .NET development http://www.componentowl.com/blog Component Owl codes Better ListView control all night so you don't have to. Tue, 04 Sep 2018 13:10:05 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 Custom label edit: How to rename file names without extension in Better ListView http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/ http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/#respond Thu, 20 Dec 2012 17:42:14 +0000 http://www.componentowl.com/blog/?p=831

Let’s suppose you want to display files with extensions in Better ListView, but allow user to rename just the file name, leaving the file extension intact after the editing.

The code for this is very simple. Just turn on label editing and handle two events: BeforeLabelEdit and AfterLabelEditCancel:

C#

[csharp gutter=”false” toolbar=”false”]
betterListView.LabelEdit = true;

betterListView.BeforeLabelEdit += BetterListViewBeforeLabelEdit;
betterListView.AfterLabelEditCancel += BetterListViewAfterLabelEditCancel;

void BetterListViewBeforeLabelEdit(object sender, BetterListViewLabelEditCancelEventArgs eventArgs)
{
string labelOriginal = eventArgs.Label;

// keep only file name in the modified label
string labelNew = Path.GetFileNameWithoutExtension(labelOriginal);

eventArgs.Label = labelNew;
}

void BetterListViewAfterLabelEditCancel(object sender, BetterListViewLabelEditCancelEventArgs eventArgs)
{
string labelOriginal = eventArgs.Label;

// add extension when editing is complete
string labelNew = String.Concat(
labelOriginal,
Path.GetExtension(eventArgs.SubItem.Text));

eventArgs.Label = labelNew;
}
[/csharp]

Visual Basic

[vb gutter=”false” toolbar=”false”]
BetterListView.LabelEdit = True

AddHandler Me.betterListView.BeforeLabelEdit, AddressOf BetterListViewBeforeLabelEdit
AddHandler Me.betterListView.AfterLabelEditCancel, AddressOf BetterListViewAfterLabelEditCancel

Private Sub BetterListViewBeforeLabelEdit(sender As Object, eventArgs As BetterListViewLabelEditCancelEventArgs)
Dim labelOriginal As String = eventArgs.Label

‘ keep only file name in the modified label
Dim labelNew As String = Path.GetFileNameWithoutExtension(labelOriginal)

eventArgs.Label = labelNew
End Sub

Private Sub BetterListViewAfterLabelEditCancel(sender As Object, eventArgs As BetterListViewLabelEditCancelEventArgs)
Dim labelOriginal As String = eventArgs.Label

‘ add extension when editing is complete
Dim labelNew As String = [String].Concat(labelOriginal, Path.GetExtension(eventArgs.SubItem.Text))

eventArgs.Label = labelNew
End Sub
[/vb]

Naturally, this feature can be used not only for file names, but whenever you would like to edit different view on the data then the displayed one.

Full version of Better ListView supports even custom embedded editing controls and you have complete control over the label editing process.

]]>
http://www.componentowl.com/blog/custom-label-edit-how-to-rename-file-names-without-extension-in-better-listview/feed/ 0
File Explorer with Better ListView http://www.componentowl.com/blog/file-explorer-with-better-listview/ http://www.componentowl.com/blog/file-explorer-with-better-listview/#respond Tue, 09 Aug 2011 16:04:31 +0000 http://www.componentowl.com/blog/?p=340 In release 2.0.2 we added a sample demonstrating how Better ListView can be used to construct folder tree and file browser to make a standalone file explorer:

File Explorer Sample

There are two controls derived from BetterListView. One for the navigation pane (folder tree on left side) and one for the file view (on the right side).

The FolderListView control allows browsing through virtual folders as well as folders on removable drives. We needed this control in our products because .NET does not provide any similar managed control (there is only FolderBrowserDialog, but we actually need a control).

You can use it for your purposes as well, it is available in Better ListView Samples source code.

Many features of Better ListView can be used to enhance file browsing, for example:

  • Drag and Drop – moving or copying files
  • Label Edit – renaming files
  • Thumbnails – display thumbnails of image files
  • Custom Tooltips – display extra information on each file item
  • Groups – organize files into groups (e.g. by size)
  • Check Boxes – select folders and sub-folders properly with three-state check boxes
  • Images – every file type could display different image (extracted icon)
  • Context Menus – do extra operations with files, like displaying file properties
  • Searching – doing keyboard search is very easy to search for some file
  • Sorting – sort files according to multiple properties (this is demonstrated in the sample)
  • Background Image – show that the user is located in special folder by ambient image on the background
]]>
http://www.componentowl.com/blog/file-explorer-with-better-listview/feed/ 0
Work in Progress: “Groups” / “Item Hierarchy” Features http://www.componentowl.com/blog/tedious-work-with-groups-and-item-hierarchy-features/ http://www.componentowl.com/blog/tedious-work-with-groups-and-item-hierarchy-features/#respond Fri, 25 Mar 2011 23:11:00 +0000 http://www.componentowl.com/blog/?p=204 We’re currently developing complex, but very useful features for the new major version of Better ListView:

  • Groups – to enable grouping items into collapsible areas with “group headers”
  • Item Hierarchy – to allow for visually organizing items like in the tree

We are facing some non-trivial obstacles on the journey You might be interested in:

Tree Structure vs List Structure

In all tree/list hybrid controls we saw there is an underlying tree structure made of nodes (like in the TreeView control). These hybrid controls are basically a tree with ability to be displayed as list.

In Better ListView, however, the primary data structure is a list, which is flat. Item hierarchy is still possible and really simple to use, just by enabling the user to set level of any item. If the item has higher level than some item above it, Better ListView will display this as a “child” item, allowing user to even collapse parent item without affecting the data structure. Sorting is also possible through “range sort”, e.g. sort only selected items or items in a certain level of hierarchy.

Compared to tree-like structure, user can still bind an IList to Better ListView or serialize/traverse through the whole item “hierarchy” with a simple foreach block.

Keeping Native Look

.NET 2.0 supports visual styles through its VisualStyleElement and VisualStyleRenderer classes, but this support is limited to basic elements. When it comes to shiny new elements that can be seen in Windows Explorer (e.g. triangular expando buttons or styles group headers), one have to hack into Windows theme to obtain correct constants. We did this nasty work to bring user visual style that matches exactly what he sees in native controls:

Visual Style Elements for Groups

Visual Style Elements for Groups

The picture shows all the elements used in “Groups” and “Item Hierarchy” features. As You can see, it is a LOT. Only group header alone has 15 (!) states that should be drawn each in its specific situation. And Better ListView will handle all of them automatically for you.

We’ve taken customized themes into consideration, as well as older themes like “Vista Basic” or “XP Luna” or “Classic”. In all cases, we test control display thoroughly to obtain consistent results (a solid reference for us is a good old Windows Explorer as it shows most up-to-date wonders of native ListView control in each version of Windows at one place).

]]>
http://www.componentowl.com/blog/tedious-work-with-groups-and-item-hierarchy-features/feed/ 0