|
-
December 12th, 2009, 02:16 AM
#1
delete selected items
hi,
i would like to add selected items in a listbox1 to listbox2.
after copying, i want it to be deleted from listbox1, its like moving an item and vice versa
the problem is i cant delete the items from where it came from.
i tried a couple of codes and the nearest is it deletes half of the selected items
Code:
private void bttndisAllow_Click(object sender, EventArgs e)
{
foreach (int i in lbAllow.SelectedIndices)
{
lbdisAllow.Items.Add(lbAllow.Items[i].ToString());
}
foreach (int i in lbAllow.SelectedIndices)
{
lbAllow.Items.Remove(lbAllow.SelectedItem);
}
}
anyone please
tia
-
December 12th, 2009, 02:52 AM
#2
Re: delete selected items
Code:
private void button1_Click(object sender, EventArgs e)
{
foreach (int i in lbAllow.SelectedIndices)
{
lbdisAllow.Items.Add(listBox1.Items[i].ToString());
}
//This is assuming you have your ListBox's Selection Mode set to MultiExtended
while (lbAllow.SelectedItems.Count > 0)
{
lbAllow.Items.Remove(lbAllow.SelectedItem);
}
}
-
December 12th, 2009, 05:43 AM
#3
Re: delete selected items
nice work! i didnt think of that. how does it work?
thanks!
-
December 12th, 2009, 09:42 AM
#4
Re: delete selected items
It checks if you have a item selected if so it removes it.
It keeps doing this for al selected items
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|