List Box

K

Kerry Hewett

Hi
I have created a list box and added a procedure which will
allow me to re-arrange the order of the list within the
box.

All is working very well. However, when I select a list
item and choose to move it up, it does not keep the
original selected item selected, but the original place in
the list!?! This is very confusing on the eye.

Does anyone have any ideas please? If you can understand
my question - well done, if you have an answer you will
become my hero. Please find a copy of the list box
movement procedure below.

Thanks very much for your time.

Kerry.

Private Sub MoveUpList(lstSrc As ListBox)
Dim intI As Integer
Dim strTemp As String
With lstSrc
For intI = 0 To .ListCount - 1
If .Selected(intI) = True And .ListIndex <> 0 Then
strTemp = .List(intI)
..RemoveItem intI
..AddItem strTemp, intI - 1
Exit For
End If
Next
End With
End Sub

Private Sub CB1_Click()
'procedure attached to my "UP" button
'seclist is the name of my listbox

Call MoveUpList(SecList)
End Sub
 
J

Jay Freedman

Hi Kerry,

Just add the line

.ListIndex = intI - 1

between the .AddItem and the Exit For. That will (re)select the item you
just moved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Drop down list control value in vba 2
Read A Text File 2
Clear Multiselect listbox 14
Module Data Storage 2
GetMultipleFiles Function 2
VBA Export to PDF 0
Multiselect listbox as criteria 6
Dynamic Function Calls 4

Top