企业级linux市场:从三分天下,到二虎竞食
2010-12-06 10:05
246 查看
一、自定义一个特性类 ListAttribute ,提供下拉列表值:
using System;
using System.Collections.Generic;
using System.Text; using System.Collections;
namespace PropertyGrid {
class ListAttribute : Attribute {
public string[] lists;
public ListAttribute() {
lists = new string[] { "A", "B", "C", "D", "E" };//如果要实现动态下拉列表,在此处初始化lists对象值
}
}
}
二、一时想不起来了,就叫它特性转换器MyConverter
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace PropertyGrid {
class MyConverter : ExpandableObjectConverter {
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
ListAttribute lst = (ListAttribute)context.PropertyDescriptor.Attributes[typeof(ListAttribute)]; StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(lst.lists);
return vals;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
return true;
}
}
}
三、应用示例:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace PropertyGrid {
class MyObject {
private int id;
public int ID {
get {
return id;
}
set {
id = value;
}
}
private string code;
public string Code {
get {
return code;
}
set {
code = value;
}
}
private string name;
[CategoryAttribute("信息"),DescriptionAttribute("名称"),TypeConverter(typeof(MyConverter)),ListAttribute()] public string Name {
get {
return name;
}
set {
name = value;
}
}
public MyObject() {
this.id = -1;
this.code = "";
this.name = "";
}
}
}
这句你不会忘记吧:propertyGrid1.SelectedObject = new MyObject();
Ok,搞定!
using System;
using System.Collections.Generic;
using System.Text; using System.Collections;
namespace PropertyGrid {
class ListAttribute : Attribute {
public string[] lists;
public ListAttribute() {
lists = new string[] { "A", "B", "C", "D", "E" };//如果要实现动态下拉列表,在此处初始化lists对象值
}
}
}
二、一时想不起来了,就叫它特性转换器MyConverter
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace PropertyGrid {
class MyConverter : ExpandableObjectConverter {
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
ListAttribute lst = (ListAttribute)context.PropertyDescriptor.Attributes[typeof(ListAttribute)]; StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(lst.lists);
return vals;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
return true;
}
}
}
三、应用示例:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace PropertyGrid {
class MyObject {
private int id;
public int ID {
get {
return id;
}
set {
id = value;
}
}
private string code;
public string Code {
get {
return code;
}
set {
code = value;
}
}
private string name;
[CategoryAttribute("信息"),DescriptionAttribute("名称"),TypeConverter(typeof(MyConverter)),ListAttribute()] public string Name {
get {
return name;
}
set {
name = value;
}
}
public MyObject() {
this.id = -1;
this.code = "";
this.name = "";
}
}
}
这句你不会忘记吧:propertyGrid1.SelectedObject = new MyObject();
Ok,搞定!
相关文章推荐
- 企业级Linux市场:从三分天下,到二虎竞食
- Linux企业级监控---zabbix安装及监控Linux服务器
- 企业级软件市场的暴风雨 CIO须未卜先知
- [RHEL5企业级Linux服务攻略]--第10季 NFS服务全攻略 推荐
- Linux企业级项目实践之网络爬虫(4)——主程序流程
- [RHEL5企业级Linux服务攻略]--第7季 Apache服务全攻略之高级配置
- [RHEL5企业级Linux服务攻略]--第9季 Squid服务全攻略之高级配置
- Linux企业级项目实践之网络爬虫(9)——通过URL抓取网页内容
- Linux企业级项目实践之网络爬虫(22)——编写爬虫系统服务控制脚本
- NIS企业级应用案例-统一Linux和Windows身份验证(三)
- MASTUDIO移动开发平台深耕企业级市场
- Linux+apache+mysql+php常规企业级配置
- 企业级Linux红旗桌面版大年夜概上岸日本
- Linux的历史、linux当前市场情况及Linux目录结构
- 市场大战:Unix失势 Linux上位?
- “农村包围城市”SQL Server 2005“绸缪”企业级市场
- Linux桌面市场呈上升趋势,现已达3%
- Linux能否守住HPC市场?
- 重度使用开源技术,网易云要用互联网IT打开企业级市场
- 中企动力“管家服务”破局企业级市场