devxlogo

MoveListboxItem – Move an item of a ListBox to another position

' Move an item of a listbox to another index'' If FROMINDEX = -1 then it moves the current highlighted itemSub MoveListboxItem(ctrl As ListBox, ByVal FromIndex As Long, _    ByVal ToIndex As Long)    Dim sText As String, lItemData As Long        ' provide a default    If FromIndex < 0 Then FromIndex = ctrl.ListIndex    ' exit if argument not in range    If ToIndex < 0 Or ToIndex > ctrl.ListCount - 1 Then Exit Sub        With ctrl        ' save text and data of the current item        sText = .List(FromIndex)        lItemData = .ItemData(FromIndex)        ' remove the item        .RemoveItem FromIndex        ' add the item        .AddItem sText, ToIndex        .ItemData(.NewIndex) = lItemData        ' select the new item        .ListIndex = ToIndex    End WithEnd Sub

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.