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. General Programming
  3. C#
  4. Change listbox item index

Change listbox item index

Scheduled Pinned Locked Moved C#
databasetutorial
2 Posts 1 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.
  • H Offline
    H Offline
    hazzem elrefai
    wrote on last edited by
    #1

    I have listbox that view data where the order of this data is important, so i need to add two buttons, to allow the user to change the item index in the listbox the first button will decrease the index by 1 (up) and the other will increase it by 1 (Down) and i do know how to change the index number thnx in advance

    H 1 Reply Last reply
    0
    • H hazzem elrefai

      I have listbox that view data where the order of this data is important, so i need to add two buttons, to allow the user to change the item index in the listbox the first button will decrease the index by 1 (up) and the other will increase it by 1 (Down) and i do know how to change the index number thnx in advance

      H Offline
      H Offline
      hazzem elrefai
      wrote on last edited by
      #2

      Thank u I did it my self and here is the code private void btn_up_Click(object sender, System.EventArgs e) { if(this.lb_target.SelectedIndex != -1) { if (this.lb_target.SelectedIndex != 0) { object tempob=this.lb_target.SelectedItem; int index=this.lb_target.SelectedIndex; this.lb_target.Items.Remove(this.lb_target.SelectedItem); this.lb_target.Items.Insert(index-1,tempob); this.lb_target.SelectedIndex=index-1; } } } private void btn_down_Click(object sender, System.EventArgs e) { if(this.lb_target.SelectedIndex < this.lb_target.Items.Count-1) { object tempob=this.lb_target.SelectedItem; int index=this.lb_target.SelectedIndex; this.lb_target.Items.Remove(this.lb_target.SelectedItem); this.lb_target.Items.Insert(index+1,tempob); this.lb_target.SelectedIndex=index+1; } }

      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