System.Windows.Forms.ListViewInsertionMark Class

Used to indicate the expected drop location when an item is dragged to a new position in a System.Windows.Forms.ListView control. This functionality is available only on Windows XP and later.

See Also: ListViewInsertionMark Members

Syntax

public sealed class ListViewInsertionMark

Remarks

You can retrieve a System.Windows.Forms.ListViewInsertionMark from the ListView.InsertionMark property of a System.Windows.Forms.ListView control and use it to visually indicate the expected drop location in a drag-and-drop operation when an item is dragged to a new position.

This feature works only when the ListView.AutoArrange property is set to true and when the System.Windows.Forms.ListView control does not sort the items automatically. To prevent automatic sorting, the ListView.Sorting property must be set to SortOrder.None and the ListView.View property must be set to View.LargeIcon, View.SmallIcon, or View.Tile. Additionally, the insertion mark feature cannot be used with the System.Windows.Forms.ListView grouping feature because the grouping feature orders the items by group membership.

The System.Windows.Forms.ListViewInsertionMark class is typically used in a handler for the Control.DragOver or Control.MouseMove event to update the position of the insertion mark as an item is dragged. It is also used in a handler for the Control.DragDrop or Control.MouseUp event to insert a dragged item at the correct location.

To update the position of the insertion mark, follow these steps:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

To insert the dragged item at the correct location, follow these steps:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

You must insert a clone of the dragged item before the original copy is removed so the index values in the ListView.Items collection are not altered before the insertion.

To ensure that the items are displayed in the same order as their index values, you must set the ListView.ListViewItemSorter property to an implementation of the IComparer interface that sorts items by index value. For more information, see the Example section.

You can modify the color of the insertion mark by using the ListViewInsertionMark.Color property. If you need the size or position of the insertion mark, you can get its bounding rectangle through the ListViewInsertionMark.Bounds property.

Note:

The insertion mark feature is available only on Windows XP and the Windows Server 2003 family when your application calls the Application.EnableVisualStyles method. On earlier operating systems, any code relating to the insertion mark will be ignored and the insertion mark will not appear. As a result, any code that depends on the insertion mark feature may not work correctly. You may want to include a test that determines whether the insertion mark feature is available, and provide alternate functionality when it is unavailable. For example, you may want to bypass all code that implements drag-and-drop item repositioning when running on operating systems that do not support insertion marks.

The insertion mark feature is provided by the same library that provides the operating system themes feature. To check for the availability of this library, call the FeatureSupport.IsPresent(object) method overload and pass in the OSFeature.Themes value.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0