propertygrid问题,StandardValuesCollection遍历在哪里实现?
下面代码我是用于测试该控件下拉框的实现。我遇到的问题是,当原数据是string类型时,选择下拉框选项,不会出现问题,但当原数据是int类型时,会出现“类型“System.String”的对象无法转换为类型“System.Int32”。”的错误提示。
我重载了ConvertFrom函数,但只能修改StandardValuesCollection集合中的一个元素(例子里总共是8个元素:0,1,2。。。),不会改全部元素。
还有就是StandardValuesCollection的遍历是在哪里实现的?
请高手指点,急!!!(新手,分数不多,笑纳)
我重载了ConvertFrom函数,但只能修改StandardValuesCollection集合中的一个元素(例子里总共是8个元素:0,1,2。。。),不会改全部元素。
还有就是StandardValuesCollection的遍历是在哪里实现的?
请高手指点,急!!!(新手,分数不多,笑纳)
namespace attributetest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = new MyObject();
}
}
public 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.obcollection);
return vals;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return true;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return true;
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
//该部分不知道该如何添加代码--!
return value;
}
}
public class ListAttribute : Attribute
{
public object[] obcollection;
public ListAttribute()
{
}
public ListAttribute(string str)
{
int i=0;
string conn="Data Source=(local);Initial Catalog=yj;Integrated Security=True;Pooling=False";
SQLTools sql=new SQLTools(conn);//自己些的sql类
DataTable dt=sql.executeQuery(str);
obcollection=new object[dt.Rows.Count];
MessageBox.Show(dt.Rows[0][0].GetType().ToString());
foreach(DataRow row in dt.Rows)
{
obcollection[i]=row[0];
i++;
}
}
}
public class MyObject
{
private int id;
[TypeConverter(typeof(MyConverter)), ListAttribute("select bdz_id from dds_biandianzhan")]
public int ID
{
get
{
return id;
}
set
{
id = value;
}
}
private string code;
public string Code
{
get
{
return code;
}
set
{
code = value;
}
}
private string name;
[TypeConverter(typeof(MyConverter)), ListAttribute("select bdz_name from dds_biandianzhan")]
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public MyObject()
{
this.id = 0;
this.code = "小旺财";
this.name = "小强";
}
}
}
...全文
相关推荐
前端开发基于history.js的HTML5与HTML4浏览器兼容方案:单页应用无刷新历史状态管理技术实现-5Z6jeSqI1792158476
内容概要:本文系统介绍了如何利用history.js实现单页应用(SPA)在HTML5c与HTML4浏览器间s草错发的无缝历史状态管理。通过封装原生History API并在不支持的浏览器中自动降级为哈希路由,history.js解决了因浏览器兼容性导致的后退按钮失效、URL混乱等问题。文章详细讲解了其核心机制,包括状态对象管理、自动模式切换(HTML5 pushState vs HTML4 哈希)、状态数据持久化以及针,对Safari、IE等浏\览器的兼容性修复方案,并提供了从入门到实战的完整示例,涵盖初始化、事,件监听、页面加载及性能优化技巧。;5Z6jeSqI1792158476 sdhmgggw168.com www.shangliangwangye.com www.sdbing.net migu.blsxex.abxlbz.sc.cn www.safespeed.net.cn
高校如何通过科技报告服务提升技术转移转化效率?.docx
科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。
科技服务机构如何提升服务大企业的技术诊断能力?.docx
科技服务机构如何提升服务大企业的技术诊断能力?
央企如何通过市场数据优化数字化转型战略?.docx
央企如何通过市场数据优化数字化转型战略?
园区如何通过数据分析实现精准招商引资?.docx
园区如何通过数据分析实现精准招商引资?


组件/控件开发
