VB icon

____A Listbox Rearrange With Mouse

Email
Submitted on: 1/31/2015 3:51:00 PM
By: Michael Anderson (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB 6.0
Views: 1920
 
     This code allows you to move items in a list box just using the mouse. Every line commented. It is very simple. I have searched high and low for a code that JUST DOES THIS without any other jargon but couldn't find any so I made it and posted it. Please give me suggestions/comments. I have edited the code to allow multi select to be enabled due to someone asking for it.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ____A Listbox Rearrange With Mouse
' Description:This code allows you to move items in a list box just using the mouse. Every line commented. It is very simple. I have searched high and low for a code that JUST DOES THIS without any other jargon but couldn't find any so I made it and posted it. Please give me suggestions/comments. I have edited the code to allow multi select to be enabled due to someone asking for it.
' By: Michael Anderson (from psc cd)
'**************************************

'add a listbox (list1) and some values in it!!!!! 
'Thats it!!!
Dim thing1 As String 
'declaring the list item to move
Dim thing2 As String 
' declaring the list item it is replacing
Dim ind As Integer 
'declaring the index of the item you wish to move
Public Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then 'left mousebutton is down
thing1 = List1.Text 
'the list item you are moving is set
ind = List1.ListIndex 'the index is set
End If
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If thing1 = List1.Text Then Exit Sub 
'to stop the program from continuously doing 
'all the functions
If thing1 = "" Then Exit Sub 
'to stop the program from continuously doing 
'all the functions
For i = 0 To List1.ListCount - 1
List1.Selected(i) = False
Next i
thing2 = List1.Text 
'list item you are replacing is set
List1.List(ind) = thing2 
'move the item above/below the item you 
'are moving to its new location
ind = List1.ListIndex 
'set the new list index of the item you are moving
List1.List(ind) = thing1 
'put the item you are moving in its new location
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.