ComboBox没有到具体一个item的Tag属性。

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;
 
 
#2楼 得分:0回复于:2007-10-12 14:30:06
谢谢,我后来自己做了个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


  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值