Results 1 to 14 of 14

Thread: Reorder ListView Items [100% Resolved]

Threaded View

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Resolved Reorder ListView Items [100% Resolved]

    I have a listview that contains 4 listviewitems. I have two buttons - Up and Down.
    What I need to do is give the functionality where if you select an item you can click one of the buttons to change
    the indexing of the item in the collection.

    So if I select item 4 and click the Up button then it will do a .Insert of the 4th item into the 3rd position and move
    the 3rd item to the 4th. Also, all the other scenerios that can come up between four items.

    I have tried this but I am getting a duplicate 4th item and losing the 3rd item.


    VB Code:
    1. Dim iSel As Integer = Me.lvwItems.FocusedItem.Index
    2. Dim iRemove As Integer = iSel
    3. If iSel >= 1 Then
    4.     'Its item 2, 3, or 4
    5.     iSel = iSel - 1
    6.     Dim itm As ListViewItem
    7.     itm = DirectCast(Me.lvwItems.FocusedItem.Clone, ListViewItem)
    8.     MessageBox.Show("iSel = " & iSel)
    9.     Me.lvwItems.Items.Insert(iSel, itm)
    10.     'remove the original item
    11.     Me.lvwItems.Items.Remove(Me.lvwItems.Items.Item(iRemove))
    12. Else
    13.     'First item - goes no where :D
    14. End If
    Thanks for any help.
    Last edited by RobDog888; May 11th, 2005 at 04:10 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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