Consulting

Results 1 to 2 of 2

Thread: Multicolumn ListBox - Moving item upwards

  1. #1

    Multicolumn ListBox - Moving item upwards

    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 -



    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!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here you are

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •