zoukankan      html  css  js  c++  java
  • VS环境下,DEV插件的ComboBoxEdit控件最简单的数据源绑定和获取方法

    使用 ComboBoxEdit 控件绑定key/value值:

    因为 ComboBoxEdit 没有 DataSource 属性,所以不能直接绑定数据源,只能一项一项的添加。

    首先创建一个类ListItem:

    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;
            }
        }
    //然后把你要绑定的key/value循环添加到ListItem类中:
     public void BindSource()
            {
                string text = string.Empty;
                string value = string.Empty;
    
                ListItem item = null;
    
                for (int i = 0; i < 4; i++)
                {
                    if (i==0)
                    {
                        text = "请选择";
                    }
                    else
                    {
                        text = "选项" + i.ToString();
                    }
                    value = i.ToString();
                    //循环添加
                    item = new ListItem(text, value);
    //将已添加的项绑定到控件的items属性中,这里只做简单的演示,可以根据自己的需求添加数据源 this.comboBoxEdit1.Properties.Items.Add(item); } }

    //获取选中项的值,其实是酱紫的;
    string text = string.Empty;
    string value = string.Empty;
    
    if (comboBoxEdit1.SelectedIndex < 0)    //小于0,表示未选择,如果是输入的也小于0
    {
         text = comboBoxEdit1.Text.Trim();     //只能获取输入的文本
    }
    else
    {
         text= (comboBoxEdit1.SelectedItem as ListItem).Text;        //获取选中项文本
         value = (comboBoxEdit1.SelectedItem as ListItem).Value;        //获取选中项的值
    }


    //OK,就是这么简单。
    提着昨日种种千辛万苦,向明天换一些美满和幸福。
  • 相关阅读:
    Java 继承
    java 封装
    单选题
    实操题
    面试题
    Linux系统常用命令
    Shell脚本编写登陆小程序.sh
    利用shell脚本实现每隔60秒磁盘内存数据监控脚本
    shell脚本一键配置本地yum源
    shell点名脚本不重复人名
  • 原文地址:https://www.cnblogs.com/jiuyueBlog/p/9035622.html
Copyright © 2011-2022 走看看