c# - CheckedListBox binding update DataSource -


here code. want update datasource when user check/uncheck item in checkedlistbox. when dump data source, nothing has been changed. why?

bindingsource source = new bindingsource();  ilist<mystr> list = new list<mystr>(); list.add(new mystr() { index = 0, name = "a", checked = false }); list.add(new mystr() { index = 1, name = "b", checked = false }); list.add(new mystr() { index = 2, name = "c", checked = true }); list.add(new mystr() { index = 3, name = "d", checked = false }); list.add(new mystr() { index = 4, name = "e", checked = false });  source.datasource = list;  ((listbox)this.cblist).datasource = source; ((listbox)this.cblist).displaymember = "name"; ((listbox)this.cblist).valuemember = "checked";  public class mystr {     public int index { get; set; }     public string name { get; set; }     public bool checked { get; set; }  } 

unfortunately, checkedlistbox not support functionality, why datasource properties hidden in designer.

you have plumbing yourself:

((listbox)this.cblist).datasource = source; ((listbox)this.cblist).displaymember = "name"; ((listbox)this.cblist).valuemember = "checked"; (int = 0; < list.count; ++i) {   cblist.setitemchecked(i, list[i].checked); } this.cblist.itemcheck += (sender, e) => {   list[e.index].checked = (e.newvalue != checkstate.unchecked); }; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -