zu generieren
Code: Select all
BindingList types = new([typeof(Foo), typeof(Bar)]);
Type? selectedType = types.SingleOrDefault(t => t.Name == "Bar");
ComboBox comboBox1 = new()
{
DataSource = types,
DisplayMember = nameof(Type.Name),
DropDownStyle = ComboBoxStyle.DropDownList,
SelectedItem = selectedType
};
Code: Select all
BindingList strings = new(new string[] { "Foo", "Bar"}.ToList());
ComboBox comboBox1 = new()
{
DropDownStyle = ComboBoxStyle.DropDownList,
};
comboBox1.Items.AddRange(strings.ToArray());
comboBox1.SelectedItem = "Bar";
< /code>
Ist dies eine Einschränkung der WinForms, oder mache ich etwas falsch? hat aber keine Antwort, die für mich funktioniert, da ich den DisplayName