Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted (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 by mutant
  • 2 months later...
  • 5 months later...
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...