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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Ordering an asp.net Listbox

Ordering an asp.net Listbox

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-net
3 Posts 2 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
    Senseicads
    wrote on last edited by
    #1

    hi Looking for a bit of help. I have an asp.net listbox. I am wanting to manually be able to order the box by clicking a button. got everything set up but I keep getting an error saying that I can't have multiple selections on the list box when it is set as a single selection. I don't really know where I am going wrong so if anyone can help me I would most appreciate it. My code for the button click is as follows. Protected Sub btOrderElementUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btOrderElementUp.Click If ltbOrderByList.Items.Count() = 0 Or ltbOrderByList.Items.Count() = 1 Then Exit Sub End If Dim liItem As ListItem Dim intItemIndex As Integer liItem = ltbOrderByList.SelectedItem intItemIndex = ltbOrderByList.SelectedIndex ltbOrderByList.Items.Insert(intItemIndex - 1, liItem) ltbOrderByList.Items.RemoveAt(intItemIndex) ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1 End Sub The last two lines are my attempt to manually set the selected item so multiple items definitly aren't selected. If there is an easier way of doing this I would also appreciate it if you could tell me too! :D Cheers Ian

    S 1 Reply Last reply
    0
    • S Senseicads

      hi Looking for a bit of help. I have an asp.net listbox. I am wanting to manually be able to order the box by clicking a button. got everything set up but I keep getting an error saying that I can't have multiple selections on the list box when it is set as a single selection. I don't really know where I am going wrong so if anyone can help me I would most appreciate it. My code for the button click is as follows. Protected Sub btOrderElementUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btOrderElementUp.Click If ltbOrderByList.Items.Count() = 0 Or ltbOrderByList.Items.Count() = 1 Then Exit Sub End If Dim liItem As ListItem Dim intItemIndex As Integer liItem = ltbOrderByList.SelectedItem intItemIndex = ltbOrderByList.SelectedIndex ltbOrderByList.Items.Insert(intItemIndex - 1, liItem) ltbOrderByList.Items.RemoveAt(intItemIndex) ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1 End Sub The last two lines are my attempt to manually set the selected item so multiple items definitly aren't selected. If there is an easier way of doing this I would also appreciate it if you could tell me too! :D Cheers Ian

      S Offline
      S Offline
      Sylvester george
      wrote on last edited by
      #2

      try this instead of

      Senseicads wrote:

      ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1

      ltbOrderByList.Items[ltbOrderByList.SelectedIndex].Selected = false; ltbOrderByList.SelectedIndex = intItemIndex - 1

      Regards, Sylvester G sylvester_g_m@yahoo.com

      S 1 Reply Last reply
      0
      • S Sylvester george

        try this instead of

        Senseicads wrote:

        ltbOrderByList.ClearSelection() ltbOrderByList.SelectedIndex = intItemIndex - 1

        ltbOrderByList.Items[ltbOrderByList.SelectedIndex].Selected = false; ltbOrderByList.SelectedIndex = intItemIndex - 1

        Regards, Sylvester G sylvester_g_m@yahoo.com

        S Offline
        S Offline
        Senseicads
        wrote on last edited by
        #3

        Thanks I was able to just set the selected to true after my clearselection. Thanks for the help. ltbOrderByList.ClearSelection() ltbOrderByList.Items(intItemIndex - 1).Selected = True So is it not possible to use selectedIndex like I was attempting to then? The intellisense says that SelectedIndex is used to "get or set" the index of the selected item? cheers Ian

        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