Answer the question
In order to leave comments, you need to log in
How to add a key and value value to the combobox, as well as fill them with data?
Good day. Having climbed the Internet, I did not find how to add values \u200b\u200bwith a key in the designer 's form.
I mean:
petya, Peter
fedya, Fedor
, etc.
Programmatically, this is done like this:
var items = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("0", "По умолчанию"),
new KeyValuePair<string, string>("1", "По категориям"),
};
comboBox_Sort.DataSource = items;
comboBox_Sort.ValueMember = "Key";
comboBox_Sort.DisplayMember = "Value";
comboBox_Sort.SelectedIndex = 0;
Answer the question
In order to leave comments, you need to log in
The solution from another forum was advice: leave it as it is. Otherwise, in designer mode, this is done clumsily.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question