M
M
maksam072016-10-23 15:52:37
C++ / C#
maksam07, 2016-10-23 15:52:37

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;

Apparently, the item "DataSource" is responsible for this, having found it in designer mode, there is an item - "Add project data source", and not understanding what needs to be done there, I closed this case and did everything in programmer mode.
So I'll repeat the question. How to do it in designer mode? The code does not look very nice when there are a lot of comboboxes and each one needs to be filled in like this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maksam07, 2016-10-24
@maksam07

The solution from another forum was advice: leave it as it is. Otherwise, in designer mode, this is done clumsily.

A
AxisPod, 2016-10-25
@AxisPod

In XAML, this is done with a bang, but in the designer it’s not worth it, but you shouldn’t leave it in the code either.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question