c# - How can I assign a Dictionary to a combobox's Items (Display and Value Members)? -
i know how assign values query listbox's display , value members:
using (sqlconnection con = new sqlconnection(reportrunnerconstsandutils.cpsconnstr)) { using (sqlcommand cmd = new sqlcommand(reportrunnerconstsandutils.selectunitsquery, con)) { cmd.commandtype = commandtype.text; using (sqldataadapter sda = new sqldataadapter(cmd)) { datatable dt = new datatable(); sda.fill(dt); ((listbox)checkedlistboxunits).datasource = dt; ((listbox)checkedlistboxunits).displaymember = "unit"; ((listbox)checkedlistboxunits).valuemember = "unit"; } } }
...and how assign single value combobox so:
list<string> schedulableweeks = platypusutils.getweekbeginnings(weeks_count).tolist(); bindingsource bs = new bindingsource(); bs.datasource = schedulableweeks; comboboxweektoschedule.datasource = bs;
...but how can assign dictionary combo box, string value of dictionary display value, , datetime valuemember? tried this:
dictionary<string, datetime> schedulableweeks = platypusutils.getweekbeginningsdict(weeks_to_offer_count); bindingsource bs = new bindingsource(); bs.datasource = schedulableweeks; comboboxweektoschedule.datasource = bs; comboboxweektoschedule.displaymember = schedulableweeks[0]; comboboxweektoschedule.valuemember = schedulableweeks[1];
...thinking access string via dictionary element 0, , datetime via element 1, doesn't compile ("argument 1: cannot convert 'int' 'string'") - same err msg both lines.
try setting key , value combobox below:
comboboxweektoschedule.displaymember = "key"; comboboxweektoschedule.valuemember = "value";
Comments
Post a Comment