KeyValuePair<byte, string> 类型的数据如何绑定到ComboBox控件上
2011-12-06 16:56
816 查看
http://blog.163.com/prince.king_521/blog/static/1068912042010101051555903/
直接上代码,KeyValuePair<byte, string> 类型的数据绑定到ComboBox控件上,并且可以指定ComboBox的DisplayMember和ValueMember。
代码如下:
/// <summary>
/// 获取数据源
/// </summary>
/// <returns></returns>
private List<KeyValuePair<byte, string>> GetData()
{
List<KeyValuePair<byte, string>> list = new List<KeyValuePair<byte, string>>();
for (int i = 0; i < 5; i++)
{
KeyValuePair<byte, string> item = new KeyValuePair<byte, string>((byte)i, "test"+i.ToString());
list.Add(item);
}
return list;
}
/// <summary>
/// 绑定列表数据到ComboBox
/// </summary>
private void BindData()
{
ComboBox cmbTest = new ComboBox();
// 获取系统声音信息并绑定到下拉控件
List<KeyValuePair<byte, string>> list = GetData();
cmbTest.DataSource = list;
cmbTest.DisplayMember = "Value";
cmbTest.ValueMember = "Key";
}
直接上代码,KeyValuePair<byte, string> 类型的数据绑定到ComboBox控件上,并且可以指定ComboBox的DisplayMember和ValueMember。
代码如下:
/// <summary>
/// 获取数据源
/// </summary>
/// <returns></returns>
private List<KeyValuePair<byte, string>> GetData()
{
List<KeyValuePair<byte, string>> list = new List<KeyValuePair<byte, string>>();
for (int i = 0; i < 5; i++)
{
KeyValuePair<byte, string> item = new KeyValuePair<byte, string>((byte)i, "test"+i.ToString());
list.Add(item);
}
return list;
}
/// <summary>
/// 绑定列表数据到ComboBox
/// </summary>
private void BindData()
{
ComboBox cmbTest = new ComboBox();
// 获取系统声音信息并绑定到下拉控件
List<KeyValuePair<byte, string>> list = GetData();
cmbTest.DataSource = list;
cmbTest.DisplayMember = "Value";
cmbTest.ValueMember = "Key";
}
相关文章推荐
- Wpf TextBox 控件如何绑定 Dictionary <int, string>
- Java 面试题之反射的应用(如何在List<String> list = new ArrayList<String>();中放入Integer类型的数据)
- 如何在ArrayList<Integer>中添加String类型数据
- Mvvm combobox绑定Dictionary<Key,Value>问题
- 如何将一个List<Map<String,String>>类型的集合数据转换成json格式输出
- KeyValuePair<TKey, TValue>泛型用法
- Map类型数据的使用和如何输出Map<String, List<>>类型的数据
- Dictionary、List<KeyValuePair<i>>的组合使用
- KeyValuePair<TKey, TValue>是DictionaryEntry的泛型版本
- 获取KeyValuePair<string, object>)泛型结构的默认值
- Winform开发之ComboBox和ComboBoxEdit控件绑定key/value数据
- C# KeyValuePair<TKey,TValue>的用法【转】
- Android Post参数提交 List<NameValuePair>,web端获取数据
- winform DataGridView绑定List<T>类型数据
- C# winform key value型数据如何绑定ComBox (hashtable,keyvaluepair,dictionary )
- Android中将List<Map<String, Object>>类型数据与字符串的相互转化
- android关于HashMap<String, Integer>取最大的value,并找出key。
- KeyValuePair<int, string>
- c++如何往map<string, set<string> > 添加数据
- KeyValuePair<bool, string>