As you can see you are removing the item which is being transferred and then you are moving to the next item in the same array, this is the point where problem arrives.
For example you moved Micheal from position 2 and just after move you delete Micheal, now the Bryan which was on position 3 have now been moved on position 2 (since Micheal has been removed from position 2). So at this point you should NOT move to next item in your loop instead you should remain on position 2. On Fri, Nov 12, 2010 at 8:02 PM, Barun <barunshres...@gmail.com> wrote: > Hi, > > I have two Listboxes side by side. First Listbox lists all employee. I > have a button to move selected employee from Listbox 1 to Listbox 2. > If i select multiple employee from ListBox 1 and click on a button to > move to selected employee to ListBox 2, then only alternate selection > is moved. > > For example. > > If ListBox 1 have employee listed as : > > 1. John > > 2. Micheal > > 3. Bryan > > After moving to ListBox 2. It shows: > > 1. John > > 2. Bryan > > My Code is: > > protected void btnAdd_Click(object sender, EventArgs e) > { > > for (int LItem = 0; LItem < this.ListBox1.Items.Count; LItem+ > +) > { > > if (this.ListBox1.Items[LItem].Selected) > { > > > this.ListBox1.Items[LItem].Selected = false; > > > this.ListBox2.Items.Add(this.ListBox1.Items[LItem]); > > > this.ListBox1.Items.Remove(this.ListBox1.Items[LItem]); > } > > } > } > } > > >