I've googled a lot. Found a lot as well. Unfortunately nothing is straight, easy and most importantly, simple. I want some guy write a method
that takes a List<string>
and removes previous Items
, then set this List<string>
.
Currently I have a method but it's not error free.
public void refreshList(List<string> list){
albumList.Items.Clear();
albumList.DataSource = list;
}
For anyone still wondering.
You can use a BindlingList and BindingSource.
BindingList<YOUR_CLASS_TYPE> bindinglist = new BindingList<YOUR_CLASS_TYPE>()
BindingSource bSource = new BindingSource();
bSource.DataSource = bindinglist;
ComboBox.DataSource = bSource;
You add all items to your bindinglist and they will be automatically updated within your combobox.
If you want a sortable combobox you can construct the BindingList with a container that inherits from IList, like List that has a sort function. You can then sort that IList reference and it will be reflected again within the combobox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With