Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Listbox sort

Listbox sort

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandraa
    wrote on last edited by
    #1

    Hello everybody, I don't know if it is posible do with a listbox or other object but i need to choose the order of a list of address for create later a route of trucks.(not sort by asc or desc) I want that a user can up o down a row of a listbox (or other object) for this election later save in a table. I am working with asp.net and vb.net I attach a picture for that you understand me better (my english is not good, sorry) Thanks for your help http://www.myleonberger.net/listbox.jpg

    Y K T 3 Replies Last reply
    0
    • S Sandraa

      Hello everybody, I don't know if it is posible do with a listbox or other object but i need to choose the order of a list of address for create later a route of trucks.(not sort by asc or desc) I want that a user can up o down a row of a listbox (or other object) for this election later save in a table. I am working with asp.net and vb.net I attach a picture for that you understand me better (my english is not good, sorry) Thanks for your help http://www.myleonberger.net/listbox.jpg

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      Well, first you need to define what is your sorting criteria. I'm not sure what your sorting criteria is from your post. Once you have that sorted out, the rest is easy. See Here[^] for some examples

      Yusuf May I help you?

      1 Reply Last reply
      0
      • S Sandraa

        Hello everybody, I don't know if it is posible do with a listbox or other object but i need to choose the order of a list of address for create later a route of trucks.(not sort by asc or desc) I want that a user can up o down a row of a listbox (or other object) for this election later save in a table. I am working with asp.net and vb.net I attach a picture for that you understand me better (my english is not good, sorry) Thanks for your help http://www.myleonberger.net/listbox.jpg

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        If I understand you correctly, you want to be able to order the items in a list box manually, to arrange the route order. Strictly the list box isn't sorted, but ordered. I assume you want this done without postback until finished, AFAIK (but I could be wrong) there are no out-the-box .net controls to do this, I found this, hopefully it will be helpful: http://www.velocityreviews.com/forums/t76756-set-display-order-of-listbox-control.html[^]

        ragnaroknrol The Internet is For Porn[^]
        Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

        1 Reply Last reply
        0
        • S Sandraa

          Hello everybody, I don't know if it is posible do with a listbox or other object but i need to choose the order of a list of address for create later a route of trucks.(not sort by asc or desc) I want that a user can up o down a row of a listbox (or other object) for this election later save in a table. I am working with asp.net and vb.net I attach a picture for that you understand me better (my english is not good, sorry) Thanks for your help http://www.myleonberger.net/listbox.jpg

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          I don't think the listbox will maintain the rearranged order if you do it with javascript on the client side. What kind of database fields do you have behind it? Is there a column to hold the sort order? You could figure out how may items you are dealing with and dynamically add hidden fields with numbers in their name MyHidden0, MyHidden1 and so on. Then with javascript in the onclientclick of your save button have a function that loops through the options in the listbox and assigns the values to the hidden field. Then you know that the item in MyHidden0 should have sort order 0 and MyHidden1 has a sort order of 1.

          S 1 Reply Last reply
          0
          • T T M Gray

            I don't think the listbox will maintain the rearranged order if you do it with javascript on the client side. What kind of database fields do you have behind it? Is there a column to hold the sort order? You could figure out how may items you are dealing with and dynamically add hidden fields with numbers in their name MyHidden0, MyHidden1 and so on. Then with javascript in the onclientclick of your save button have a function that loops through the options in the listbox and assigns the values to the hidden field. Then you know that the item in MyHidden0 should have sort order 0 and MyHidden1 has a sort order of 1.

            S Offline
            S Offline
            Sandraa
            wrote on last edited by
            #5

            the first thanks for your ideas, even I am thinking about it because I don't know like up or down items of my listbox with 2 button (up, down) and that user see it. The idea is can put order in listbox for later print a sheet of route for trucks, the first item will be the first customer for distribute and last item will be the last customer for distribute but doesn't exist a rule to order like asc or desc etc, it must be done by user like he wants. the idea after listbox is ordered is save this information to table for later print. Well, at the moment I will be happy to know like can up or down items of listbox with two buttons, later know like save it in array. I imagine that for sample if the item 7 of my listbox I push 3 times my button of "up" it will be my future item 4 but the problem is that my old item 4 now will be item 5 and my old item 6 will be item 7, haha I am losing myself :confused: Thanks for your ideas ;)

            S 1 Reply Last reply
            0
            • S Sandraa

              the first thanks for your ideas, even I am thinking about it because I don't know like up or down items of my listbox with 2 button (up, down) and that user see it. The idea is can put order in listbox for later print a sheet of route for trucks, the first item will be the first customer for distribute and last item will be the last customer for distribute but doesn't exist a rule to order like asc or desc etc, it must be done by user like he wants. the idea after listbox is ordered is save this information to table for later print. Well, at the moment I will be happy to know like can up or down items of listbox with two buttons, later know like save it in array. I imagine that for sample if the item 7 of my listbox I push 3 times my button of "up" it will be my future item 4 but the problem is that my old item 4 now will be item 5 and my old item 6 will be item 7, haha I am losing myself :confused: Thanks for your ideas ;)

              S Offline
              S Offline
              Sandraa
              wrote on last edited by
              #6

              I found the solve very easy :) You only call to this sub from button up Regards

              Sub MoveSelectedItemUp(ByVal Box As ListBox)
                  Dim Index As Integer = Box.SelectedIndex    'Index of selected item
                  Dim Swap As Object = Box.SelectedItem       'Selected Item
                  If Not (Swap Is Nothing) Then               'If something is selected...
                      Box.Items.RemoveAt(Index)                   'Remove it
                      Box.Items.Insert(Index - 1, Swap)           'Add it back in one spot up
                      'Box.SelectedItem = Swap                     'Keep this item selected
                  End If
              End Sub
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups