我有一个winforms应用程序,其中我想绑定这些值
Disponible(D):D
NSFP(S):S
Archivé(A):A
NC(N):N
到DevExpressComboBoxEdit
控件,即项目文字为Disponible (D), NSFP (S), Archivé (A), NC (N)
,值为D,S,A,N
,因为项目来源类型为varchar(1)
。
那我该如何完成这项任务呢?
答案 0 :(得分:1)
要完成此任务,我建议您使用LookUpEdit编辑器:
LookUpEdit lookUpEdit = new LookUpEdit();
var dataSource = new List<Data> {
new Data(){ Value = 'D', Display ="Disponible (D)"},
new Data(){ Value = 'S', Display ="NSFP (S)"},
new Data(){ Value = 'A', Display ="Archivé (A)"},
new Data(){ Value = 'N', Display ="NC (N)"},
};
lookUpEdit.Properties.DataSource = dataSource;
lookUpEdit.Properties.Columns.Add(new LookUpColumnInfo("Value") { Visible = false });
lookUpEdit.Properties.Columns.Add(new LookUpColumnInfo("Display"));
lookUpEdit.Properties.DisplayMember = "Display";
lookUpEdit.Properties.ValueMember = "Value";
lookUpEdit.Properties.ShowHeader = false;
lookUpEdit.EditValue = 'A';
此处Data
类如下所示:
public class Data {
public string Display { get; set; }
public char Value { get; set; }
}