Nexus Posted August 5, 2003 Posted August 5, 2003 can somebody tell me what to write after listbox1.Items.Remove so that it will remove the currently selected item? Quote
*Experts* mutant Posted August 5, 2003 *Experts* Posted August 5, 2003 (edited) Do this: ListBox1.Items.Remove(ListBox1.SelectedItem) SelectedItem returns the currently selected item. This will delete it. You can also delete the current item using SelectedIndex and RemoveAt: ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) :) Edited August 5, 2003 by mutant Quote
Sylonious Posted October 23, 2003 Posted October 23, 2003 (edited) How do you delete an item without selecting it? listbox.items.Removeat(1) does not work for me. Edited October 23, 2003 by Sylonious Quote
Leaders dynamic_sysop Posted October 23, 2003 Leaders Posted October 23, 2003 like this ... ListBox1.Items.Remove(ListBox1.Items.Item(1)) '/// in that case, removes the item with an index of 1 Quote
hungheykwun Posted March 25, 2004 Posted March 25, 2004 when i use ListBox1.Items.Remove(ListBox1.SelectedItem) or the selected index...i get this Cannot modify the Items collection when the DataSource property is set. this happens only when i have one item in my list to remove Quote
Celeron Posted March 25, 2004 Posted March 25, 2004 If there is only 1 item, try using ListBox1.Items.Clear() Quote
hungheykwun Posted March 26, 2004 Posted March 26, 2004 listbox remove item If there is only 1 item' date=' try using ListBox1.Items.Clear()[/quote'] same error if i use .item.add to add each individually, then its fine. but if i use valuemember and displaymember to load data frm db, the below error occurs Cannot modify the Items collection when the DataSource property is set. Quote
JABE Posted March 26, 2004 Posted March 26, 2004 Set DataSource to Nothing/null prior to removing items. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.