Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

sorting items in a listview

Hello, I am having a bit of a problem ordering items in a listview.  I actually have two listviews.  On the top one, you double click an item, and it goes down to the bottom one.  This works perfectly.  However, I would like them not to remain in the order that they are in the top listview.  For instance, I want whatever item I click on first to be the first item in the bottom one, second to be the second in the bottom one, and so forth.  Is this possible?  Thanks in advance.
1 Solution
hmm.. not exactly sure what you're saying but hopefully this will help.  I just whipped it up as an example maybe you could look over and find useful?

Dim itmX As ListItem, tmpPosition As Integer
tmpPosition = ListView2.ListItems.Count - 1
Set itmX = ListView2.ListItems.Add(tmpPosition, ListView1.SelectedItem.Key, ListView1.SelectedItem.Text)
itmX.SubItems(1) = ListView1.SelectedItem.SubItems(1)
itmX.SubItems(2) = ListView1.SelectedItem.SubItems(2)
ListView1.ListItems.Remove ListView1.SelectedItem.Index
selectgt's solution looks right to me, as the first parameter of .ListItems.Add determines WHERE in the listview the new item is added to.

On the other hand, a listview will naturally add items in the order they are placed, so you should not have had a problem in the first place!

My guess is that you probably have set the second listview to have the same sort order as your first one.

Please make sure that your bottom ListView has the sorted property set to false (and that you do not set it to true in code)

If it was set to true, then your original program should already sort the items properly. If this is not the case, then the selectgt's code should solve the problem for you.
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
afeldAuthor Commented:
Sorry, I let this one get away and forgot about it.  Thanks all for answers.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now