`

ComboBox设置Key,Value

    博客分类:
  • C#
阅读更多
 class Option
    {
      public string Key { get; set; }   
      public string Value { get; set; } 
      public Option(string pKey, string pValue)   
      {   
       this.Key = pKey;   
       this.Value = pValue;   
      }    
    }


设置
   Option option = new Option("1", "金额");   
   this.combobox1.Items.Add(option );   
   // 在此可以增加N个   
   this.combobox1.Items.Add(option );   
   // 对应 ListItem 的  Value  显示值
   this.combobox1.DisplayMember = "Value";
   // 对应 ListItem 的  Key    隐藏值
   this.combobox1.ValueMember = "Key";


读取
   Option option = (Option )comboBox1.SelectedItem;   
   MessageBox.Show(option .Key + option .Value); 
分享到:
评论

相关推荐

    java ComboBox

    扩张了java的JComboBox, 扩展功能有 ...//参数为Map类型,key对应为comboBox下拉显示的内容,对应的value为提示语 PS:MyComboBox只是我根据自己需要扩展的,调用JComboBox本有的方法可能会影响控件效果,没测试过!!

    java JComboBox的事件处理

    java JComboBox的事件处理 java JComboBox的事件处理 java JComboBox的事件处理

    DEV控件中的ComboBoxEdit控件如何绑定数据库中的数据

    DEV控件中的ComboBoxEdit控件绑定数据库中的数据,主要的绑定方式下拉框中显示Name,但是在选中使用时,使用的是对应的ID。

    C# DataGridView即可下拉选择又可手动输入内容的列

    注:本程序为个人原创,转载时请注明来源! 该类是基于DataGridViewColumn封装的一个即可下拉选择又可手动输入内容的列。...5,获取到的单元格的值Value(也即Row[i].Cell[j].Value)为隐藏值(也即Key)

    excel VBA登陆实验

    key = ComboBox_name.SelText Set myarea = Sheets("sheet1").Columns(1).Find(key) If myarea.Rows.Count > 0 Then If myarea.Offset(0, 1).Value = TextBox_un.Text Then MsgBox "登陆成功!" login.Hide '隐藏...

    VB自动关机源码.rar

    ComboBox1.SelectedIndex = 2 '设置默认选项 "每天" ComboBox2.SelectedIndex = 4 '设置默认选项 "关机" Timer1.Start() readReg() '读取存放在注册表的信息 StrToItems() '把字符串的信息读取到ListBox ...

    C# WinForm控件美化之ImageComboBox

    ImageIndexer.Key = value; } } [Browsable(false)] public ImageComboBox ImageComboBox ...{ get ...{ return _imageComboBox; } } internal Image Image ...{ get ...{ int actualIndex = ...

    CSerialPort串口类最新修正版2016-08-02

    添加QueryKey()和Hkey2ComboBox两个方法,用于自动查询当前有效的串口号。 by liquanhai on 2014-12-18 增加一些处理措施,主要是对减少CPU占用率 by itas109 on 2016-05-07 http://blog.csdn.net/itas109 修复...

    C#全能速查宝典

    1.5.8 ContainsValue方法——确定哈希表是否包含特定值 101 1.5.9 Count属性——获取数目 102 1.5.10 GetEnumerator方法——循环访问对象 103 1.5.11 GetEnvironmentVariables方法——检索环境变量 104 1.5.12 ...

    CSerialPort串口类最新修正版2017-02-14

    添加QueryKey()和Hkey2ComboBox两个方法,用于自动查询当前有效的串口号。 by liquanhai on 2014-12-18 增加一些处理措施,主要是对减少CPU占用率 by itas109 on 2016-05-07 http://blog.csdn.net/itas109 修复...

    Silverlight2.0功能展示Demo源码

    IsolatedStorageSettings.ApplicationSettings - 按应用程序保存的 key-value 字典表 15、Silverlight(17) - 2.0数据之详解DataGrid, 详解ListBox 介绍 Silverlight 2.0 详解DataGrid, 绑定数据到ListBox: ...

    CSerialPort串口类最新修正版2016-08-10

    添加QueryKey()和Hkey2ComboBox两个方法,用于自动查询当前有效的串口号。 by liquanhai on 2014-12-18 增加一些处理措施,主要是对减少CPU占用率 by itas109 on 2016-05-07 http://blog.csdn.net/itas109 修复...

    delphi通用函数单元一

    function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'): string; {测试通过} {* 扩展整数转字符串函数 Example: IntToStrEx(1,5,'0'); 返回:"00001"} function IntToStrSp(Value: Integer; ...

    TMS Pack for FireMonkey2.3.0.1

    Fixed : Issue with scrolling and selecting value in iOS in TTMSFMXSpinner Fixed : Issue with escape key not cancelling edit mode in TTMSFMXGrid v1.6.0.1 Fixed : Issue with double databinding ...

    VB编程资源大全(英文源码 控制)

    1 , TaskBar_v0.5.zip "Form_Taskbar is a control for Visual Basic which, once placed onto a form, makes the form act like the Taskbar (minus the Start Menu)." -- David Newcum<END><br>2 , ...

    VB.NET Developer's Guide(4574).pdf

    a value or whether we are using the Call statement. It makes the code much more readable and is a new standard for VB programmers that is consistent with the standard that nearly all other languages ...

    VB编程资源大全(英文源码 其它)

    noreturn.zip Disable the Return Key in a TextBox<END><br>60,entertab.zip Use the Enter Key Like a Tab<END><br>61,detenter.zip Detect When the User Presses Enter<END><br>62,prntscrn.zip ...

Global site tag (gtag.js) - Google Analytics