DevExpress ComboBoxEdit应用

2021-07-14 更新
1、给ComboBoxEdit添加items
string[] portName=new string[]{"COM1","COM2"};
ComboBoxEdit1.Properties.Items.AddRange(portName);

2、只能选择不能在里面 输入数据
combboxEdit.propoties.textEditStyle=DisableTextEditor
3、显示值与实际值(键值对模块)
 //建一个类
 public class ComboxData
 {
     public string Text { set; get; }

     public string Value { set; get; }

     public override string ToString()
     {
         return Text;
     }
 }
//给comboBoxEdit填充数据
DataTable dt = new DataTable();//这里是个空的,实际不能为空的dataTable,
foreach(DataRow dr in dt.Rows)
{
    ComboxData data = new ComboxData();
    data.Text = dr["ModuleName"].ToString();
    data.Value = dr["Id"].ToString();
    comboBoxEdit1.Properties.Items.Add(data);
}
//获取显示值与实际值
string text = (cbModuleType.SelectedItem as ComboxData).Text;
string value = (cbModuleType.SelectedItem as ComboxData).Value;

评论