c# - Can't get Value and DisplayMember from CheckedListBoxControl bound to LINQ -
the question has been asked before on stackoverflow might think it's duplicate, i've tried number of solutions, i'm still stuck.
i have winforms checkedlistboxcontrol bound linq query , fail value , displaymembers.
below tries value , displaymember values:
var avail = c in dc.costcenters select new { item = c.costcenterid, description = c.costcenterid + ": " + c.description }; mylist.datasource = avail; mylist.displaymember = "description"; //retrieval: foreach (var item in mylist.checkeditems) { datarowview row = item datarowview; //try 1: row empty string displaymember = item["description"]; //try 2: cannot apply indexing [] expression of type 'object' var x = item[0]; //try 3: cannot apply indexing [] expression of type 'object' row3 = ((datarowview)mylist.checkeditems[item]).row; //try 5 million: compile error - invalid arguments }
assuming want get/display valuemembers/displaymembers: sample provide assume ienumerable<dynamic>
linq query. have converted test scenario list<dynamic>
:
list<dynamic> list = new list<dynamic> { new { item = 1, description = "1: item1"}, new { item = 2, description = "2: item2"} };
just add bindingsource checkedlistbox:
bindingsource bindingsource = new bindingsource(list, null); checkedlistbox1.datasource = bindingsource; checkedlistbox1.valuemember = "item"; checkedlistbox1.displaymember = "description";
when have selected items , want check it:
var checkeditems = checkedlistbox1.checkeditems; foreach (dynamic checkeditem in checkeditems) { console.writeline("valuemember: " + checkeditem.item); // or whatever code have }
hope helps!
Comments
Post a Comment