C# add list of strings to combobox and when item is remove automatic affect to list -


i want add strings list combobox, , when 1 of item removed ui, want automatically effect on list (that list remove selected string).

what best tehnic kind of problems.

example:

list<string> users = new list<string>(){ "frsuser", "secuser", "thruser", "fouuser" };  private void frmmain_load(object sender, eventargs e) {     foreach(var user in users)         cmbuser.items.add(user); }  private void btnremove_click(object sender, eventargs e) {     cmbuser.items.removeat(cmbuser.selectedindex);     // should removed here?      users.removeat(cmbuser.selectedindex); } 

this done using bindingsource handles interaction between collection of combobox items , list

private void frmmain_load(object sender, eventargs e) {     bindingsource bs = new bindingsource();     bs.datasource = users;     c.datasource = bs; } 

now @ button click event use code

private void btnremove_click(object sender, eventargs e) {     if(c.selectedindex == -1)         return;      bindingsource bs = c.datasource bindingsource;     bs.removeat(c.selectedindex);      // show updated list      foreach(string u in users)         console.writeline(u); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -