devxlogo

Moving Items in a List Box

Moving Items in a List Box

To change the item’s location by dragging the mouse in a listbox, follow this tip:

 Sub List1_MouseDown (Button As _        Integer, Shift As Integer, X As _        Single, Y As Single)                Old_Index = List1.ListIndex        TmpText = List1.TextEnd Sub

While the button mouse is on, this event saves the current indexand text to variables:

 Sub List1_MouseUp (Button As Integer,_        Shift As Integer, X As Single, _        Y As Single)        New_Index = List1.ListIndex        If Old_Index  New_Index Then                List1.RemoveItem Old_Index                List1.AddItem TmpText, New_Index        End IfEnd Sub

When the button mouse is off, a new variable sets the new mouselocation. To test if it is the same, remove the old item and addthe new item with the text saved in TmpText.

General Declarations:

 Dim TmpText As StringDim Old_Index As IntegerDim New_Index As Integer
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