Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
207 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...