PDA

View Full Version : Multicolumn ListBox - Moving item upwards



avadhutd2
11-09-2009, 12:22 AM
Hi,

I need help regarding the code below. This code moves the selected item in the listbox UP in the list. Actually, the listbox that I am working on is a 2 column listbox. Hence I have 2 values corresponding to a item in a listbox.

e.g ListBox may look like something like -

http://www.dicks-blog.com/blogpix/ReOrderLb1.gif

What modification can be done in the code below so that I can move both columns of the selected item UP in a column wise format.


Dim intCurrentIndex As Integer
Dim strCurrentText As String

With ListBox1
If .ListIndex > 0 Then
intCurrentIndex = .ListIndex
strCurrentText = .List(.ListIndex)
.RemoveItem .ListIndex
.AddItem strCurrentText, intCurrentIndex - 1
.ListIndex = intCurrentIndex - 1
.Selected(intCurrentIndex) = False
.Selected(intCurrentIndex - 1) = True
End If
End With

Please let me know....Thanks!

Bob Phillips
11-09-2009, 01:28 AM
Here you are



Dim strCurrentText As String
Dim strCity As String

With ListBox1
If .ListIndex > 0 Then
intCurrentIndex = .ListIndex
strCurrentText = .List(.ListIndex)
strCity = .List(.ListIndex, 1)
.RemoveItem .ListIndex
.AddItem strCurrentText, intCurrentIndex - 1
.List(intCurrentIndex - 1, 1) = strCity
.ListIndex = intCurrentIndex - 1
.Selected(intCurrentIndex) = False
.Selected(intCurrentIndex - 1) = True
End If
End With