Change listbox item index
-
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
-
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
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; } }