Results 1 to 4 of 4

Thread: ListBox/ListView Move Item with Mouse

Hybrid View

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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:
    • 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.
    These properties are removed:
    • 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.

    Name:  MoveItemLists.jpg
Views: 6242
Size:  49.0 KB
    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.

    Update 2010-Feb-12:
    • 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.
    Attached Files Attached Files
    Last edited by JuggaloBrotha; Jun 3rd, 2010 at 12:39 PM. Reason: Updated attachments
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: ListView Move Item with Mouse

    Sorry. I didn't notice your submission til after i posted mine.

  3. #3

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: ListBox/ListView Move Item with Mouse

    I've made a CheckedListBox control now too.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,467

    Re: ListBox/ListView Move Item with Mouse

    if you need a reorderable listview / listbox with dragdrop effects + without the superfluous properties, take a look at my submission:

    reOrderable DnD listview / listbox

    which is also based on the same code project article

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width