c# - Set both Text and Value property of ComboBox in design time -
i need add following items combo box.
value displaytext
mpost posted
call calling
rscan re-scan
these items static, , not retrieved database... hence thought of assigning these in design time itself.
i'm unable use items property asks 1 value per item... please help.
ps : in case suggesting bindingsource, please give me example. not able find one.
you use bindinglist<keyvaluepair<string, string>>
:
var items = new bindinglist<keyvaluepair<string, string>>(); items.add(new keyvaluepair<string, string>("mpost", "posted")); items.add(new keyvaluepair<string, string>("call", "calling")); items.add(new keyvaluepair<string, string>("rscan", "re-scan")); mycombobox.datasource = items; mycombobox.valuemember = "key"; mycombobox.displaymember = "value";
i don't think you're going find solution simpler or more straightforward this. put in form's constructor (after initializecomponent
--and way, i'd attach event handlers intend add combobox after point in code) , you're good.
as why there isn't easier way: honestly, i'd typical example of how solutions become more complex more flexible try make them. don't me wrong; combobox quite nice little control. thing is, it's designed take any legitimate backing source, not table, or list, or collection of items 2 properties. since can take data source, concept of strict key/value pairing stripped of special status. wouldn't make sense provide special gui adding items 2 properties (though might convenient in particular situation).
Comments
Post a Comment