B
B
bqio2020-09-03 16:14:03
C++ / C#
bqio, 2020-09-03 16:14:03

How to properly bind data to ComboBox?

List<Scenario> scenarios = new List<Scenario>();
List<Map> maps = new List<Map>();

Scenario scenario = new Scenario();
Scenario scenario1 = new Scenario();
Map map = new Map();
Map map1 = new Map();

scenario.ScenarioID = 1;
scenario1.ScenarioID = 2;
map.Name = "Russia";
map1.Name = "USA";

scenario.Map = map;
scenario1.Map = map1;

maps.Add(map);
maps.Add(map1);
scenarios.Add(scenario);
scenarios.Add(scenario1);

BindingSource source = new BindingSource();
BindingSource source1 = new BindingSource();

source.DataSource = scenarios;
source1.DataSource = maps;

comboBox1.DataSource = source;
comboBox1.DisplayMember = "ScenarioID";

comboBox2.DataSource = source1;
comboBox2.DisplayMember = "Name";


I want the first box to display a list of scenarios, and the second box to have the full list of cards, but the card that is linked to the scenario is selected. How to tie it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Janus74, 2020-09-06
@Janus74

5f5504ccda4a7555819648.png
for the place of List try ObservableCollection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question