Removing the Items from ListBox or ComboBox

ismts

New member
Joined
Jul 26, 2007
Messages
3
Programming Experience
Beginner
Hi,

I have added the items to the ListBox using Binding to the datatable.
ListBox1.DisplayName="SupplierName"
ListBox1.ValueMember="SupplierID"
ListBox1.DataSource = DT

Now i need to remove the items from the ListBox.
ListBox1.Items.Clear() - Throws Exception at the runtime.
Could you please let me know how can I Remove the items from the ListBox.

Thanks for the help!!...
 
Thanks for the information.
Is any other way to remove the items from the ListBox. If so Please let me knw...

Thanks for the Help!!!!
 
yes. previously i was adding the items to the listbox using ListBox1.Items.Add("xxx") and clearing the same using ListBox1.Items.Clear().
But i would like to know when ListBox is binded to the DataTable using DataSource property, How can can remove the items from List box.
Thanks for giving the solution by clering datatable itself.
It would have been more helpful if other solution is present for removing the items from the ListBox.
 
There is no other solution! The items ARENT IN THE LISTBOX, so they cannot be removed from it. The listbox is showing only what it finds in the datatable! How do you expect to clear it any other way?

Imagine you look in through a window and see that the room is untidy. The window is showing you what the room is like. You say "gee, i wish that window showed me a tidy room" - how can the window show you a tidy room? Tidy the room the window is showing - there is no other way!

Oh, wait.. no.. I considered another option.. Make a new combobox and position it on top of the old one.. That would be like sticking a large picture of a tidy room on top of the window..
 
Imagine you look in through a window and see that the room is untidy..
How does that analogy relate to two-way data binding? Shouldn't we be able to tell someone through the window to tidy their room? :confused:
 
How does that analogy relate to two-way data binding? Shouldn't we be able to tell someone through the window to tidy their room? :confused:

No. The window/combo is functioning as a view of the model (in MVC architecture). There is nothing that states that the window/combo must also be a Controller of the model and indeed, databound combos are only Views of the Model they are bound to. Other properties can be bound to a second Model, in which case the combo functions as aController for that Model


The analogy holds because you cannot tell a window to tidy a room; if you tell someone through the window, to tidy the room, youre actually instructing a slave operator to rearrange the model; the window itself is not doing anything other than providing a view of the model
 
Back
Top