Feb 9th, 2010, 11:15 AM
ListBox/ListView Move Item with Mouse
First off I didn't write the actual code for the re-positioning of the ListViewItem, but I did convert it from c# to vb.net and I did make it it's own control rather than handling the mouse events on the form. Here's the CodeProject article I used to create the control: Manual reordering of items inside a ListView
and here's the guy who made it: mav.northwind
Anyways, this control is inherited from the Framework's ListView and has these properties added:
These properties are removed:
- ItemMoveEnabled (Boolean) items can only be rearranged if this is True, otherwise it's disabled.
- InsertionLineColor (Color) this control draws a line between items to show where the item would be place and the color of the line is handled by this property. Default is Red.
- MultiSelect (Boolean) Right now this can only be handled 1 item at a time and Multiselect has to be set to False so this property is suppressed and hidden for now, I may get it to work with multiple items later, we'll see.
Events that have been added:
- ItemMoveEnabledChanged this fires when the ItemMoveEnabled property has changed.
- ItemMoved this fires right after you release the item with the mouse and if the item was actually moved. e.CurrentIndex (Int) is the index of where the item was and e.NewIndex (int) is where the item has moved to. This is particularly useful if you have a collection and you need to rearrange the associated item in the collection.
To use the control simply add the MoveItemListView.vb/MoveItemListBox.v, or both, and ItemMovedEventArgs.vb files to your project, build it then in the form designer it appears in the ToolBox at the top just drag and drop it on the form and viola use it like a regular ListView.
- Fixed an issue with the ListView in which the InsertionLine wouldn't disappear if the mouse left the LV during an item re-position.
- Moved the ItemMovedEventArgs class to a separate file, which is required by both the MoveItemListView but also the MoveItemListBox
- Applied the LV's item re-position to work with a ListBox and made a control with the same events added and added it here.
Update 2010-Feb-18: Added a CheckedListBox.
Update 2010-June-03: Added the ToolBoxBitmap.
Last edited by JuggaloBrotha; Jun 3rd, 2010 at 12:39 PM.
Reason: Updated attachments
Click Here to Expand Forum to Full Width
Survey posted by VBForums.