RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB4,VB5,VB6
Expertise: beginner
Aug 19, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 item

Sub 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 With
End Sub

Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date