c# - 允许在可浏览属性的组合框中复制/粘贴
问题描述
我有一个具有复杂可浏览属性的控件,它在表单中显示该类型的所有控件的列表,但我想允许在组合框中复制和粘贴控件的名称。我使用了 a TypeConverter
,但组合框的项目消失了。还有另一种方法吗?或者我如何返回GetStandardValues
函数中的默认项目列表?我试图返回基本函数,但它不起作用。
public class SubflowchartConverter : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
FlowChart flowchart = context.Instance as FlowChart;
if (flowchart != null)
return true;
else
return base.GetStandardValuesSupported(context);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return base.GetStandardValues(context);
}
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, CultureInfo culture, object value)
{
if (value is string)
{
string flowchartName = value.ToString();
if (flowchartName == "(none)")
return null;
FlowChart flowchart = context.Instance as FlowChart;
if (flowchart.Parent.Controls.ContainsKey(flowchartName))
{
return flowchart.Parent.Controls[flowchartName];
}
}
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
if (value == null)
return "(none)";
FlowChart flowchart = value as FlowChart;
if (flowchart != null)
return flowchart.Name;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
解决方案
推荐阅读
- javascript - 如何为 Gmail 应用程序使用访问令牌?
- flutter - Flutter 中的 RangeError 不超过 Range
- xslt - 删除 '.' 之前的前缀 (点)
- php - laravel 单行动态值
- export - 使用 AnyChart 通过 jpg/png 导出图表图,得到输出的一半
- javascript - 反应 setState 方法不更新状态
- netlogo - Netlogo : 滑块比率驱动 > Ifelse 随机结果之一
- php - 由于 laravel 中的不活动错误导致页面过期
- amazon-web-services - AWS Fargate 服务和服务发现
- elasticsearch - 从弹性搜索中的字段中获取唯一值