PropertyGrid控件显示数组

我了个擦啊啊啊 2020-10-15 01:59:45
自己写了个TypeConverter把数组转换成string
不使用TypeConverter效果

使用TypeConverter效果

我只想把Double[] Array变成字符串,可是转换后,展开的内容也变了,有大佬知道怎么弄吗


private double[] exposeTime = new double[] { 1, 2, 4 };
[Browsable(true)]
[ReadOnly(false)]
[Category("相机参数")]
[DisplayName("曝光时间")]
[XmlElement("曝光时间")]
[TypeConverter(typeof(ArrayConverter))]
public double[] ExposeTime
{
get
{
return exposeTime;
}
set
{
exposeTime = value;
}
}




public class ArrayConverter : ExpandableObjectConverter
{



public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType)
{

if (destinationType == typeof(System.String) && value is double[])
{
var v = value as double[] ;
string s=string.Empty;
foreach(var a in v)
{
s += a.ToString() + ",";
}
return s.TrimEnd(',');
}
return base.ConvertTo(context, culture, value, destinationType);

}
}
...全文
2901 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangling2 2021-03-10
  • 打赏
  • 举报
回复
public class ArrayConverter : ExpandableObjectConverter { public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (destinationType == typeof(System.String) && value is double[]) { var v = value as double[]; string s = string.Empty; foreach (var a in v) { s += a.ToString() + ","; } return s.TrimEnd(','); } return base.ConvertTo(context, culture, value, destinationType); } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { return new PropertyDescriptorCollection(null); } }
ziqi0716 2020-10-16
  • 打赏
  • 举报
回复
Model修改下啦,别用数组,用枚举试试. 或者把你的需求再描述下~

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧