gpt4 book ai didi

c# - 使用 C# 填充 ComboBox

转载 作者:IT王子 更新时间:2023-10-29 04:11:43 25 4
gpt4 key购买 nike

我想用以下内容填充组合框:

可见项目/项目值(value)

English / En

Italian / It

Spainish / Sp

etc....

有什么帮助吗?

还有可能在填充 Combobox 之后,将其设置为只读吗?

最佳答案

定义一个类

public class Language
{
public string Name { get; set; }
public string Value { get; set; }
}

然后...

//Build a list
var dataSource = new List<Language>();
dataSource.Add(new Language() { Name = "blah", Value = "blah" });
dataSource.Add(new Language() { Name = "blah", Value = "blah" });
dataSource.Add(new Language() { Name = "blah", Value = "blah" });

//Setup data binding
this.comboBox1.DataSource = dataSource;
this.comboBox1.DisplayMember = "Name";
this.comboBox1.ValueMember = "Value";

// make it readonly
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

关于c# - 使用 C# 填充 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2417960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com