devxlogo

MoveListboxItem – Move an item of a ListBox to another position

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

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

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.

About Our Journalist