改变 propertygrid 控件的编辑风格(4)——加入选择列表
2007-09-29 09:44
453 查看
适用场合:
限制选择输入
步骤一:定义从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 );
}
public override bool canconvertfrom( itypedescriptorcontext context, type sourcetype)
{
if (sourcetype == typeof(string))
{
return true;
}
return base.canconvertfrom(context, sourcetype);
}
public override object convertfrom(
itypedescriptorcontext context,
system.globalization.cultureinfo culture,
object v )
{
if (v is string)
{
foreach (dictionaryentry myde in _hash)
{
if( myde.value.equals((v.tostring())) )
return myde.key;
}
}
return base.convertfrom(context, culture, v);
}
public override object convertto(
itypedescriptorcontext context,
system.globalization.cultureinfo culture, object v ,
type destinationtype)
{
if (destinationtype == typeof(string))
{
foreach (dictionaryentry myde in _hash)
{
if( myde.key.equals(v) )
return myde.value.tostring();
}
return "";
}
return base.convertto(context, culture, v, destinationtype);
}
public override bool getstandardvaluesexclusive(
itypedescriptorcontext context)
{
return false;
}
}
}
步骤二:定义 comboboxitemtypeconvert 的派生类,派生类中实现父类的抽象方法:
public abstract void getconverthash();
示例如下:
using system;
using system.collections;
using system.componentmodel;
namespace blog.csdn.net.zhangyuk
{
public class propertygridboolitem : comboboxitemtypeconvert
{
public override void getconverthash()
{
_hash.add(0,"是");
_hash.add(1,"否");
}
}
public class propertygridcomboboxitem : comboboxitemtypeconvert
{
public override void getconverthash()
{
_hash.add(0,"炒肝");
_hash.add(1,"豆汁");
_hash.add(2,"灌肠");
}
}
}
步骤三:编辑属性类,指定编辑属性。示例如下:
namespace blog.csdn.net.zhangyuk
{
public class someproperties
{
private string _finished_time = "";
……
// 布尔
bool _bool = true;
[
description("布尔"),
category("属性"),
typeconverter(typeof( propertygridboolitem ))
]
public int 布尔
{
get { return _bool == true ? 0 : 1; }
set { _bool = (value == 0 ? true : false); }
}
// 选择列表
int _comboboxitems = 0;
[
description("选择列表"),
category("属性"),
typeconverter(typeof( propertygridcomboboxitem ))
]
public int 选择列表
{
get { return _comboboxitems; }
set { _comboboxitems = value; }
}
……
}
}
步骤四:设置propertygrid的属性对象。示例如下:
private void form1_load(object sender, system.eventargs e)
{
this.propertygrid1.selectedobject = new someproperties();
[align=left] } [/align]
限制选择输入
步骤一:定义从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 );
}
public override bool canconvertfrom( itypedescriptorcontext context, type sourcetype)
{
if (sourcetype == typeof(string))
{
return true;
}
return base.canconvertfrom(context, sourcetype);
}
public override object convertfrom(
itypedescriptorcontext context,
system.globalization.cultureinfo culture,
object v )
{
if (v is string)
{
foreach (dictionaryentry myde in _hash)
{
if( myde.value.equals((v.tostring())) )
return myde.key;
}
}
return base.convertfrom(context, culture, v);
}
public override object convertto(
itypedescriptorcontext context,
system.globalization.cultureinfo culture, object v ,
type destinationtype)
{
if (destinationtype == typeof(string))
{
foreach (dictionaryentry myde in _hash)
{
if( myde.key.equals(v) )
return myde.value.tostring();
}
return "";
}
return base.convertto(context, culture, v, destinationtype);
}
public override bool getstandardvaluesexclusive(
itypedescriptorcontext context)
{
return false;
}
}
}
步骤二:定义 comboboxitemtypeconvert 的派生类,派生类中实现父类的抽象方法:
public abstract void getconverthash();
示例如下:
using system;
using system.collections;
using system.componentmodel;
namespace blog.csdn.net.zhangyuk
{
public class propertygridboolitem : comboboxitemtypeconvert
{
public override void getconverthash()
{
_hash.add(0,"是");
_hash.add(1,"否");
}
}
public class propertygridcomboboxitem : comboboxitemtypeconvert
{
public override void getconverthash()
{
_hash.add(0,"炒肝");
_hash.add(1,"豆汁");
_hash.add(2,"灌肠");
}
}
}
步骤三:编辑属性类,指定编辑属性。示例如下:
namespace blog.csdn.net.zhangyuk
{
public class someproperties
{
private string _finished_time = "";
……
// 布尔
bool _bool = true;
[
description("布尔"),
category("属性"),
typeconverter(typeof( propertygridboolitem ))
]
public int 布尔
{
get { return _bool == true ? 0 : 1; }
set { _bool = (value == 0 ? true : false); }
}
// 选择列表
int _comboboxitems = 0;
[
description("选择列表"),
category("属性"),
typeconverter(typeof( propertygridcomboboxitem ))
]
public int 选择列表
{
get { return _comboboxitems; }
set { _comboboxitems = value; }
}
……
}
}
步骤四:设置propertygrid的属性对象。示例如下:
private void form1_load(object sender, system.eventargs e)
{
this.propertygrid1.selectedobject = new someproperties();
[align=left] } [/align]
相关文章推荐
- 改变 PropertyGrid 控件的编辑风格(4)——加入选择列表
- 改变 PropertyGrid 控件的编辑风格(1)——加入日期控件-.NET教程,组件控件开发
- 改变 PropertyGrid 控件的编辑风格(1)——加入日期控件
- 改变 propertygrid 控件的编辑风格(2)——编辑多行文本
- 改变 PropertyGrid 控件的编辑风格(2)——编辑多行文本
- 改变 propertygrid 控件的编辑风格(3)——打开对话框
- 改变 PropertyGrid 控件的编辑风格(3)——打开对话框
- 列表选择编辑风格-报表系统
- 改变PropertyGrid编辑风格(转)
- 日期选择下拉列表小控件
- Android控件BottomSheet实现底边弹出选择列表
- 选择列表控件的使用(PickList)
- andriod———1.实现原生登录注册。 2.首页完成商品列表展示点击相对应的商品ID进入商品详情 3.商品详情页面展示数据,点击加入购物车进入购物车页面 4.购物车页面完成购物车编辑,删除,功能
- 可编辑的列表控件
- PropertyGrid控件下拉列表
- 下拉列表选择控件, 用于替换原生的 select 控件
- MFC List Control 控件添加单元格编辑和单元格下拉列表项
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- iOS中button选择其中一个角改变弧度(适用其他控件)
- ADF中选择表行后改变当前行的编辑状态