首页 > 其他 > 详细

DevExpress ComboboxEdit绑定key value值

时间:2021-02-26 09:46:57      阅读:37      评论:0      收藏:0      [点我收藏+]

DevExpress中ComboboxEdit是没有DataSource属性的,所以不能绑定数据源,只能一项一项的添加。

我现在需要给ComboboxEdit绑定键值对的属性,具体操作如下:

1、新建一个ListItem类,继承object。

public class ListItem : Object
    {
        public string Text { get; set; }

        public string Value { get; set; }

        public ListItem(string text, string value)
        {
            this.Text = text;
            this.Value = value;
        }

        public override string ToString()
        {
            return this.Text;
        }
    }

2、绑定数据源

string text = string.Empty;
string value = string.Empty;
ListItem item = null;
StartBranchId.Properties.Items.Clear();
foreach (DataRow row in data.Tables["Branch"].Rows)
{
    item = new ListItem(row["xName"].ToString(), row["Id"].ToString());
    this.StartBranchId.Properties.Items.Add(item);
}

3、取值

MessageBox.Show((StartBranchId.SelectedItem as ListItem).Text);
MessageBox.Show((StartBranchId.SelectedItem as ListItem).Value);

DevExpress ComboboxEdit绑定key value值

原文:https://www.cnblogs.com/mikemao/p/14450516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!