Item Reordering

Changing item order by dragging items can be turned on by setting ItemReorderMode to one of the following values:

The reordering is realized through Drag and Drop mechanism.

Item reordering can supports groups and item hierarchy.

Target location of reordered items is displayed using Insertion mark. If the reordering cannot be performed (e.g. when inserting item between its own children), then the insertion mark is displayed as disabled and the reordering will not be performed.

Reordering Options

There are several item reordering options to adjust the feature for working with groups and hierarchical items. These options can be used as flags of the enumm property ItemReorderOptions:

None of the extra options are on by default so the default value is ItemReorderOptions.None.

Auto-Expansion Checking

Auto expansion checking is performed during item reordering and looks whether it is valid to auto expand item over which mouse cursor hovers. By default, there is only one situation when auto expansion is not allowed: Item which is auto-collapsed will not be than auto-expanded again.

It is possible to add custom checking (e.g. when some items or groups should not expand when user drags items over it) by handling CheckAutoExpand event and than set BetterListViewCheckAutoExpandEventArgs.IsValid to false whenever you want to deny auto-expansion. Event data contains both source and target items.

Item Reordering Checking

Checking for item reorder validity is performed during item reordering. It looks for possible reasons why the reordering may not be valid (e.g. reordering parent item into itself) and sets BetterListViewItemReorderEventArgs.InvalidationReasons property. The property can have the following flags:

You can override the OnCheckItemReorder method or add CheckItemReorder event handler to add your own validation.

Event data contains read-only property called IsValid, which is true whenever InvalidationReasons property is equal to BetterListViewInvalidationReasons.None.

Item reorder validity influences appearance of insertion mark (will be displayed in disabled state) and whether the reordering will be performed.

Item Reordering Info

When user releases mouse button, the ItemReorder event is raised. You can find useful properties in the event data:

Sample Source Code

C#

this.listView.BeginUpdate();

this.listView.Columns.Add("column");

this.listView.Items.AddRange(
    new[]
    {
        "first item",
        "second item",
        "third item",
        "fourth item",
        "fifth item"
    });

// enable item reordering
this.listView.ItemReorderMode = BetterListViewItemReorderMode.Enabled;

this.listView.EndUpdate();

Visual Basic

ListView.BeginUpdate()

ListView.Columns.Add ("column")

ListView.Items.AddRange (
    New String() { _
                     "first item",
                     "second item",
                     "third item",
                     "fourth item",
                     "fifth item"
                 })

' enable item reordering
ListView.ItemReorderMode = BetterListViewItemReorderMode.Enabled

ListView.EndUpdate()