使用 C# 填充 ComboBox [英] Populating a ComboBox using C#

查看:31
本文介绍了使用 C# 填充 ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to populate a combobox with the following:

可见项目/项目价值

English / En

Italian / It

Spainish / Sp 

etc....

有什么帮助吗?

也有可能在填充组合框后,使其只读?

Also it is possible that after populating the Combobox, to make it read only?

推荐答案

定义一个类

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# 填充 ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆