The Wrecking Bawl

Destructuring query language, one keyword at a time.


News


I don't know if this would be considered a bug or not, or if I'm just missing something, but when you use ListBox.DataSource in Windows.Forms (.Net 2.0), and you add or remove an item from an ArrayList that is set as the DataSource, there is no method to refresh the listbox.  The only thing I know that works is setting the DataSource to null and then setting it back to the ArrayList.  That just doesn't seem right. 

 

addendum (the next day):  I may have found another bug!  When I move an item up or down in my ArrayList and then rebind it to the ListBox, I still want the item that was moved to be selected.  I tried ListBox.ClearSelected() followed by ListBox.SelectedIndex = originalIndex, but that resulted in both the zero-index item being selected and the original item being selected.  I ended up having to do the following line twice in a row before setting the selection:

ListBox.SelectedIndex = -1;


Comments

Gravatar # re: ListBox bug in C#?
Posted by Ingo Fabbri on 10/16/2007 8:51 AM
THX. that helped me a lot. this "bug" did drive me nuts :D
Gravatar # re: ListBox bug in C#?
Posted by Marko on 2/5/2008 4:24 AM
What I found you have to do on a multi-select list box to set the SelectedIndex is this:

lbListBox.SelectedIndices.Clear();
lbListBox.SetSelected(index,true);

This will set the selected index as well as select it on the screen. Change the SetSelected value to false and it will set the selected index, however, will not select the item on the screen.
Gravatar # re: ListBox bug in C#?
Posted by Alex Humphrey on 6/26/2008 7:39 PM
ListBox will bind correctly to an instance of System.ComponentModel.IBindingList such as System.ComponentModel.BindingList<T>. If your design is tightly bound to using an ArrayList, try creating a subclass of ArrayList that implements IBindingList.
Gravatar # re: ListBox bug in C#?
Posted by Lucious on 3/22/2009 11:30 PM
I have populated data to a ListBox using dataView (sql information) and bind the listbox, and now im having a problem with changing the indexValue from the listbox and save it back to the database after positioning items. I have managed to move the items up and down but item values doesnt change. For example i want to be able to move items up and down and save them back with their new position.

Can somebuddy please help me on this?
Can you also notify me on my email of the answer? ldzhivhuwo@npa.gov.za
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: