给datagridview的某一下拉列表列添加:
0 否
1 是
否和是value值,0、1是KEY值
代码怎么写
第一步:建立KeyValue:
public class KeyValue { private int key; private string value; public int Key { get { return key; } set { value = key; } } public string Value { get { return value; } set { value = this.value; } } public KeyValue(int key, string value) { this.key = key; this.value = value; } }
第二部:调用
List<KeyValue> data = new List<KeyValue>(){ new KeyValue(1,"文本1"), new KeyValue(2,"文本2"), new KeyValue(3,"文本3"), }; type_kind.DataSource = data; type_kind.DisplayMember = "Value"; type_kind.ValueMember = "key";