Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 194681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:36:58+00:00 2026-05-11T16:36:58+00:00

I have a list of data that users are able to control the sort

  • 0

I have a list of data that users are able to control the sort order of.

It looks something like this

Apples     /\  \/
Oranges    /\  \/
pears      /\  \/
banana     /\  \/
Pineapples /\  \/
etc        /\  \/

the /\ and / are meant to be up and down arrows

When the user clicks up i want to retrieve the current sort order and take one away fro it (so it has a smaller value and will be higher in the sort order.

When the user clicks down I do the opposite

I guess I also need to establish if there is already something else in the list with the new value I want to assign and adjust that item’s sort order in the opposite direction

Does this seem like a good way to achieve this?

Or is there a smarter way?

Anyone got any sample code. I am using .net 3.5 so linq is OK

The list is stored in an in memory cache – IList<mycustomobj>

any suggestions gratefully received

EDIT:
The issues I am worried about are when there is no sort order initially – everything will be zero. And my suggested algorithm has an implicit assumption that the sort order will always be continuous. But what happens when a row is deleted? there will be a gap in the list of sort orders, so simply adding 1 and taking away 1 might not make any difference – how do I handle this scenario?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:36:58+00:00Added an answer on May 11, 2026 at 4:36 pm

    That’s a way to do it. In my application we either use drag-and-drop, or have one up arrow and one down arrow to move the selected element up/down.

    If you have some property determining the sort order, when the user clicks the up arrow you just need to permutate the current element’s sort position with the previous element’s sort position, unless it’s the first element (do nothing in that case). Use the reverse logic for the down arrow…

    Edit:

    If your items don’t have a sort position yet, you could just go through your list and assign a sort position from 1 to n.
    In case of a deleted row, decrease the sort position of all following items by one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of data that looks like the following: // timestep,x_position,y_position 0,4,7
I have a list control in Flex that has been data bound to an
I have a .NET repeater control that is data-bound to a List. As part
I have a rather large list of data that contains 5 properties per element.
i have a large list of static data from a server that i load
I have an ItemsControl that is data bound to a list of decimal s.
I have a view that has a list of jobs in it, with data
this might be a stupid question, but I'm using asp.net list control that creates
If I have a list of data in a text file seperated by a
I currently have a list view which has several rows of data and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.