ComBox绑定枚举
(转自:http://blog.csdn.net/chao88552828/article/details/9903159)
/// <summary>
/// 参数枚举
/// </summary>
public enum ParematerType
{
//酒店
酒店 = ,
//景区等级
景区 = ,
//餐馆/农家乐 等级
餐馆 = ,
//购物
购物 = ,
//娱乐
娱乐 = ,
}
/// <summary>
/// 窗体加载参数类型
/// </summary>
private void initializeComBox()
{
Type parematerType = typeof(SystemEnum.ParematerType);
foreach (int index in Enum.GetValues(parematerType))
{
string name = Enum.GetName(parematerType, index);//ex:餐馆
string value = index.ToString();//ex:9
//需要增加引用:System.Web
//引用命名空间:using System.Web.UI.WebControls;
//ListBox 也可用这个方法
ListItem item = new ListItem();
item.Text = name;
item.Value = value;
cmbParematerType.Items.Add(item);
}
}
///获取下拉框的选中内容
private void getSelectComBox()
{
ListItem item =(ListItem)(cmbParematerType.SelectedItem);
string name = item.Text;
string value = item.Value;
}
///获取ListBox的选中内容
private void getSelectsListBox()
{
//lbShow是ListBox的名称
for (int i = ; i < lbShow.SelectedIndices.Count; i++)
{
int index = this.lbShow.SelectedIndices[i];
string value= ((ListItem)(lbShow.Items[index])).Value;
string name = ((ListItem)(lbShow.Items[index])).Text;
}
} ----------------------------------------------------------------
ps:模板化
private void initializeComBox<T>(ComboBox combox)
{
var itemType = typeof(T);
foreach (int index in Enum.GetValues(itemType))
{
var item = new DictionaryEntry();
item.Key = Enum.GetName(itemType, index);
item.Value = index.ToString();
combox.Items.Add(item);
}
combox.DisplayMember = "Key";
combox.ValueMember = "Value";
}
ComBox绑定枚举的更多相关文章
- DataTrigger 绑定枚举
在触发器中绑定枚举类型: <ControlTemplate.Triggers> <DataTrigger Binding="{Binding CheckStateEnum} ...
- c#中DropDownList控件绑定枚举数据
c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...
- 绑定枚举到dropdownlist
pageTools.BindEnumToDropdownList(typeof(enumDealerArea), ddlBmwArea, new ListItem("--请选择--" ...
- ASP.NET Core 四种方式绑定枚举值
前言 本节我们来讲讲在ASP.NET Core MVC又为我们提供了哪些方便,之前我们探讨过在ASP.NET MVC中下拉框绑定方式,这节我们来再来重点看看枚举绑定的方式,充分实现你所能想到的场景,满 ...
- 整理:WPF中Xaml中绑定枚举的写法
原文:整理:WPF中Xaml中绑定枚举的写法 目的:在Combobox.ListBox中直接绑定枚举对象的方式,比如:直接绑定字体类型.所有颜色等枚举类型非常方便 一.首先用ObjectDataPro ...
- winform Combox绑定数据时不触发SelectIndexChanged事件
做了一个仓库选择的联动,选了仓库选其下的货区,选了货区选其下的货架分区.每个combox初始化.绑定数据是都会触发SelectIndexChanged事件,相当头疼. 后来无意中在网上看到了一种方法— ...
- winform开发中绑定combox到枚举
开发中需要根据下拉框的选择处理一些业务逻辑,使用ID值或Text值都不利于代码维护,所以可以写个扩展方法绑定到枚举上. public static class Extensions { /// < ...
- silverlight中Combox绑定数据以及动态绑定默认选定项的用法
在Sliverlight中,经常要用到下拉框Combox,然而Combox的数据绑定却是一件令初学者很头疼的事情.今天就来总结一下下拉框的使用方法: 下面写一个简单的例子吧.先写一个日期的Model, ...
- c# select标签绑定枚举,并以Description做Text显示
今天在做项目时遇到一个问题: 开发中有些字段是枚举类型如 Dept 企业表中可能有个字段 Property 性质 0:事业单位,1:私企,2:外企,但有时我们不会单独为性质这个字段定义一张表, 而是在 ...
随机推荐
- 访问hdfs里的文件
准备工作: 给hdfs里上传一份用于测试的文件 [root@master ~]# cat hello.txt hello 1 hello 2 hello 3 hello 4 [root@master ...
- Notepad++ 更换主题
到Textmate Theme Directory下载主题: 用文本编辑器把它打开,复制所有代码,贴到theme converter page里,然后“Download”: 保存: 在Notepad+ ...
- Oracle Shared Pool 原理
Oracle Shared Pool 原理 由于shared pool中最重要的是library cache,所以本文主要讲解Library cache的结构,library cache latch, ...
- python全栈开发从入门到放弃之字典的应用
1.存值 info_dic={'name':'egon','age':18,'sex':'male'} info_dic['job']='IT' #根据key来存值 print(info_dic) 输 ...
- 基于WinIO 3.0实现驱动级键盘模拟输入
基于WinIO 3.0实现驱动级键盘模拟输入 一个业务场景需要使用驱动级的键盘模拟,折腾了2天,总结一下,为后人节省时间. 限制条件: 1.需要真实PC机,虚拟机不行 2.仅支持PS/2 键盘(指外接 ...
- Codeforces Round #395 (Div. 2) C. Timofey and a tree
地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ...
- Jconsle
1. jconsole 远程连接: JConsole很好用,可以解决很多疑难杂症.但远程连接需要设置一下Java opt才可以使用.以下是步骤: 1). 在java opt下添加如下内容: 如果是无须 ...
- LeetCode: Next Greater Element I
stack和map用好就行 public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { ...
- MySQL-5.7 高阶语法及流程控制
1.标签语句 [begin_label:] BEGIN [statement_list] END [end_label] [begin_label:] LOOP statement_list END ...
- 文件操作工具类: 文件/目录的创建、删除、移动、复制、zip压缩与解压.
FileOperationUtils.java package com.xnl.utils; import java.io.BufferedInputStream; import java.io.Bu ...