ComboBox没有到具体一个item的Tag属性。
来源:互联网 发布:好一点的耳环品牌 知乎 编辑:程序博客网 时间:2024/05/17 08:15
ComboBox没有到具体一个item的Tag属性。
你可以使用一个结构体或对象添加到到Items,以此来扩充Item的属性。这样像Tag属性就容易实现了。
你只需重写结构体或类的ToString方法。比如:
struct itemEx
{
public object Tag;
public string Text;
public itemEx(object tag, string text)
{
this.Tag = tag;
this.Text =text;
}
public override string ToString()
{
return this.Text;
}
}
itemEx item = new itemEx(123, "123");
this.combobox1.Items.Add(item);
//取值:
itemEx item =(itemEx) this.combobox1.SelectedItem;
item.Tag;
你可以使用一个结构体或对象添加到到Items,以此来扩充Item的属性。这样像Tag属性就容易实现了。
你只需重写结构体或类的ToString方法。比如:
struct itemEx
{
public object Tag;
public string Text;
public itemEx(object tag, string text)
{
this.Tag = tag;
this.Text =text;
}
public override string ToString()
{
return this.Text;
}
}
itemEx item = new itemEx(123, "123");
this.combobox1.Items.Add(item);
//取值:
itemEx item =(itemEx) this.combobox1.SelectedItem;
item.Tag;
谢谢,我后来自己做了个shortstringdirectory,你的是另一个参考不错,谢谢
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace M_RC
{
class ShortStringDictionary:DictionaryBase
{
#region
public String this[String key]
{
get
{
return ((String)Dictionary[key]);
}
set
{
Dictionary[key] = value;
}
}
public ICollection Keys {
get{
return(Dictionary.Keys);
}
}
public ICollection Values
{
get
{
return (Dictionary.Values);
}
}
public void Add(String key, String value)
{
if (Dictionary.Contains(key) != false)
return;
Dictionary.Add(key, value);
}
public bool contains(String key)
{
return (Dictionary.Contains(key));
}
public void Remove(String key)
{
Dictionary.Remove(key);
}
protected override void OnInsert(object key, object value)
{
if (key.GetType() != typeof(System.String))
throw new ArgumentException("键值必须是一个字符串类型。", "key");
else
{
String strKey = (String)key;
//if (strKey.Length < 10)
// throw new ArgumentException("键值不能少于10个字符");
}
if (value.GetType() != typeof(System.String))
throw new ArgumentException("键值必须是一个String类型", "value");
else {
String strValue = (String) value;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
}
}
protected override void OnRemove( Object key, Object value ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
}
protected override void OnSet( Object key, Object oldValue, Object newValue ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
if ( newValue.GetType() != typeof(System.String) )
throw new ArgumentException( "newValue must be of type String.", "newValue" );
else {
String strValue = (String) newValue;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "newValue must be no more than 5 characters in length.", "newValue" );
}
}
protected override void OnValidate( Object key, Object value ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
if ( value.GetType() != typeof(System.String) )
throw new ArgumentException( "value must be of type String.", "value" );
else {
String strValue = (String) value;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
}
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace M_RC
{
class ShortStringDictionary:DictionaryBase
{
#region
public String this[String key]
{
get
{
return ((String)Dictionary[key]);
}
set
{
Dictionary[key] = value;
}
}
public ICollection Keys {
get{
return(Dictionary.Keys);
}
}
public ICollection Values
{
get
{
return (Dictionary.Values);
}
}
public void Add(String key, String value)
{
if (Dictionary.Contains(key) != false)
return;
Dictionary.Add(key, value);
}
public bool contains(String key)
{
return (Dictionary.Contains(key));
}
public void Remove(String key)
{
Dictionary.Remove(key);
}
protected override void OnInsert(object key, object value)
{
if (key.GetType() != typeof(System.String))
throw new ArgumentException("键值必须是一个字符串类型。", "key");
else
{
String strKey = (String)key;
//if (strKey.Length < 10)
// throw new ArgumentException("键值不能少于10个字符");
}
if (value.GetType() != typeof(System.String))
throw new ArgumentException("键值必须是一个String类型", "value");
else {
String strValue = (String) value;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
}
}
protected override void OnRemove( Object key, Object value ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
}
protected override void OnSet( Object key, Object oldValue, Object newValue ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
if ( newValue.GetType() != typeof(System.String) )
throw new ArgumentException( "newValue must be of type String.", "newValue" );
else {
String strValue = (String) newValue;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "newValue must be no more than 5 characters in length.", "newValue" );
}
}
protected override void OnValidate( Object key, Object value ) {
if ( key.GetType() != typeof(System.String) )
throw new ArgumentException( "key must be of type String.", "key" );
else {
String strKey = (String) key;
//if ( strKey.Length > 5 )
// throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
}
if ( value.GetType() != typeof(System.String) )
throw new ArgumentException( "value must be of type String.", "value" );
else {
String strValue = (String) value;
//if ( strValue.Length > 5 )
// throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
}
}
#endregion
}
}
- ComboBox没有到具体一个item的Tag属性。
- 解决combobox没有item的特别tag的问题
- 控件显示内容的绑定类 combobox 为每一item 加tag
- ComboBox的Item
- Combobox的IsSynchronizedWithCurrentItem 属性
- 一个子组件没有添加到显示列表前,它的属性不能修改
- 把枚举类型的值绑定到一个ComboBox中
- 为ComboBox的item设置图片
- 一个ComboBox的Bug
- char [] 到 LPWSTR转换的一个具体应用
- 具有只读属性的ComboBox
- ComboBox的一些属性应用
- 小技巧:SP下,如何使用ListBox+SPIN组成一个没有空隙的ComboBox
- 解决QML开发中ComboBox中一个已选择项没有清除的问题
- C# 控件的Tag属性
- C#中ComboBox的SelectedIndexChanged事件获取Tag值
- VC6.0导出内容到excel的简单代码例子,具体方法没有记录
- 简述view的tag属性的使用以及将其运用到代码布局
- 加锁解锁PHP实现
- pthread_once 和 pthread_key
- Moodle(2.1+)新搭建完毕后要做的事情(2.3.1+更新)
- Java常用类库(一)
- int A[nSize],其中隐藏着若干0,其余非0整数,写一个函数int Func(int* A, int nSize),使A把0移至后面,非0整数移至后面
- ComboBox没有到具体一个item的Tag属性。
- EXCEL 截取一段,做除法运算,精确两位小数
- SSI技术详解
- rmp包的软件的安装和卸载
- 静态库和动态库编译方法和开发上的重要性
- memcache中内存管理源码剖析
- 一些很好的技术学习博客
- hdu 1062 Text Reverse(水)
- 火狐正用心打造平板浏览器