sorting items in a listview

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-05-01
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.
Question by:afeld
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

selectgt earned 200 total points
ID: 8082457
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
LVL 27

Expert Comment

ID: 8082802
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.

Expert Comment

ID: 8900551
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?

Author Comment

ID: 8903052
Sorry, I let this one get away and forgot about it.  Thanks all for answers.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question