Start New Discussion within our Software Development Community

I have 6 rows of items in a ListView within 2 columns that are listed like so:

1    Milk
2    Pepsi
3    Juice
4    Water
5    Coffee
6    Tea

I'm trying to make it so when you modify the number in the first column, it will sort the list based on the first column's number in ascending order. But that's the easy part.

The hard part is making it so that if you change the number in the first column to a number that already exists in the list it will bump the existing row down and change the numbers in the first column to correspond to the change. For example...

If I change the 6 in the first column to a 5, the fifth row will be bumped down to row 6, the sixth row will be bumped up to row 5 and the number in the first column will increase/decrease to compensate the change.

How can this be accomplished?

Here is a way(maybe it is not the best):

1. write your sort procedure
2. define two form properties or variables : ListIndex and ValueFromIndex
3. when user clicks on a row (OnSelectIdem maybe, or OnClick), do
- check if the previous row(the row with the index ListIndex) has the value changed (it is different from ValueFromIndex). If so, sort the list
- update ListIndex and ValueFromIndex with the values from the current item

Ionut

Comments
Thanks!
This question has already been answered. Start a new discussion instead.