In my application, i have a combobox. It uses as an item, a name(string) and an ID(int)
I have written some code that updates what is being displayed as i change a value of an item.
((Item)(joinedFilesCombobox.SelectedItem)).PictureID = 0;
joinedFilesCombobox.Items.Refresh();
With this code, when i click on the dropdown icon of the combobox, my item is correctly updated in the list, but not the current selected item. In order to correctly refresh the current displayed item i just modified, i have to do a little trick :
int curr = joinedFilesCombobox.SelectedIndex;
joinedFilesCombobox.SelectedIndex = curr+1;
joinedFilesCombobox.SelectedIndex = curr;
Doing this updates the view of the currently selected item.
But this solution isn't clean. Is there a cleaner way to do that ?
为了使其正常工作,您的Item
应实现INotifyPropertyChanged
接口并在PictureID
属性的setter中引发PropertyChanged
事件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.