日期:2012-02-25  浏览次数:20555 次

改变 PropertyGrid 控件的编辑风格(4)——加入选择列表

 

张昱e-zhangyu@vip.sina.com 效果:

适用场合:

限制选择输入

 

步骤一:定义从UITypeEditor 继承的抽象类:ComboBoxItemTypeConvert。示例如下:

using System;

using System.Collections;

using System.ComponentModel;

 

namespace blog.csdn.net.zhangyuk

{

     /// IMSTypeConvert 的摘要说明。

     /// </summary>

     public abstract class ComboBoxItemTypeConvert : TypeConverter

     {

         public Hashtable _hash = null;

 

         public ComboBoxItemTypeConvert()

         {

              _hash = new Hashtable();

              GetConvertHash();

         }

 

         public abstract void GetConvertHash();

 

         public override bool GetStandardValuesSupported( ITypeDescriptorContext context )

         {

              return true;

         }

 

         public override StandardValuesCollection GetStandardValues(

ITypeDescriptorContext context)

         {

              int [] ids = new int [ _hash.Values.Count ];

 

              int i=0;

              foreach (DictionaryEntry myDE in _hash)

              {

                   ids[i++] = (int)(myDE.Key);

              }

 

              return new StandardValuesCollection( ids );