关于PropertyGrid 下拉列表,C#实现,其实比较简单
来源:互联网 发布:java static 变量 编辑:程序博客网 时间:2024/04/29 07:46
一、自定义一个特性类 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,搞定!
- 关于PropertyGrid 下拉列表,C#实现,其实比较简单
- propertyGrid 下拉列表,收藏
- PropertyGrid控件下拉列表
- 下拉列表简单实现跳转
- C# 实现颜色下拉列表框
- WPF-002 下拉列表的简单实现
- WPF:下拉列表的简单实现
- iOS 简单实现下拉列表框
- C# PropertyGrid多行编辑实现
- 简单实现PropertyGrid编辑Dictionary功能
- 实现propertyGrid下拉自定义窗体并且不可编辑
- C# 下拉列表框
- 关于下拉列表问题
- ASP.NET C#生成下拉列表树实现代码
- mysql+php select 下拉列表树的简单实现
- 使用each方法实现简单的下拉列表联动
- 用HTML+CSS实现简单的下拉列表
- 最简单的鼠标悬停,实现下拉列表功能 bootstrap
- 可激活的 Jini 服务:实现 RMI 激活
- Table 排序
- Basic Translation Rules for TC
- 学习J2EE所看的书籍
- 16个经典面试问题回答思路
- 关于PropertyGrid 下拉列表,C#实现,其实比较简单
- checkbox的全选和反选
- sql语法速成
- 8个要领_推荐自己
- 下拉列表框的值可手工输入
- 表单标签
- 网络安装linux for IBM X61 7675
- 4步骤_职业生涯
- sql模糊查询总结