locked
Items collection cannot be modified when the DataSource property is set RRS feed

  • Question

  • User2145053574 posted

    hello,


    I got 2 listboxes in a window form, one on left and one on right. The
    1st listbox have some items while the 2nd listbox is empty. Also there
    are 2 buttons between the 2 listboxes which used to move item from/to
    the 1st and 2nd listbox

    My problem here is that after I bind the data to the 1st listbox (from
    a dataTable, using DisplayMember and ValueMember) , and I try to move 1
    of the item from this 1st listbox to the 2nd listbox and I want that
    the selected item is also removed from the 1st listbox by:

    lbMembers2.Items. Add(lbMembers1. Text);
    lbMembers1.Items. Remove(lbMembers 1.Text);

    But the selected item is not removed from the 1st listbox.

    Also on deselect button when i move item from 2nd listbox to 1st
    listbox,it displays error message "Items collection cannot be modified
    when the DataSource property is set."


    can any one give me the solution to my problem.


    thanks and regards,

    prasanth.

    Wednesday, February 17, 2010 11:12 AM

Answers

  • User2145053574 posted

    Hello,


    Thanks for your reply,


    my problem is resolved.


    instead of giving listbox1.items.remove(listitem);


    i used listbox1.items.remove(listbox1.selecteditem);


    regards,

    prasanth.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2010 12:00 AM

All replies

  • User2130758966 posted

    For Windows Forms help you should ask your questions here:

    I am not being awkward, its just that a lot of developers don't use Win Forms here (myself included) so you wont get the quickest / best answers.


    I would guess that when you use the DataSource property and you want to make a change to the items collection you would change the underlying data source and then rebind the collection.

    Wednesday, February 17, 2010 12:13 PM
  • User2145053574 posted

    Hello,


    Thanks for your reply,


    my problem is resolved.


    instead of giving listbox1.items.remove(listitem);


    i used listbox1.items.remove(listbox1.selecteditem);


    regards,

    prasanth.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2010 12:00 AM