C # Force ListBox for updating items

I will subclass the standard ListBox control. I am notified of changes to any of the items added to the list. The challenge is to update the text displayed by the ListBox for the item to be modified.

I know that I could just delete the changed item and add it again, but this seems not preferable for obvious reasons.

+5
source share
2 answers

Unfortunately, data binding in ListViewdoes not support regular (item) notification changes ( FooChanged/ INotifyPropertyChanged). However, if you know about the change, you can get a list to re-link yourself. Since you are a subclass, you can call:

this.RefreshItems();

or for one item:

this.RefreshItem(index);

Otherwise, since this is not publicly available, you can simulate it by changing DisplayMember:

lb.DisplayMember = "";
lb.DisplayMember = "Bar";

A bit hacked, maybe, but it works, and supports the current selection, etc. (unlike cleaning DataSource).

+15
source

? ListBox. ObjectListView, , .

+1

All Articles