用集合编辑器编辑自定义类集合属性并自动生成代码出现的问题
目的:使用过DataGridView的都清楚,通过DataGridView的属性Columns能通过集合编辑器生成本地化的代码,因此实现的功能就是有个自定义的类,比如叫DataGridViewTopRowCell对象,在DataGridView中添加了此对象的集合,通过集合编辑器生成本地化的相关代码。
已实现的功能:
已经实现自定义的类DataGridViewTopRowCell关联相关的集合编辑器,但是添加了集合项之后编译提示错误:
错误 1 无效的 Resx 文件。未能加载 .RESX 文件中使用的类型 System.Collections.Generic.List`1[[WindowsFormsApplication1.DataGridViewTopRowCell, WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089。请确保已在项目中添加了必要的引用。 行 134,位置 5。 E:\projects\vs\WindowsFormsApplication1\WindowsFormsApplication1\Form3.resx 134 5 WindowsFormsApplication1
有没有人遇到过此问题?求帮忙解决。
相关代码如下:
1、DataGridViewTopRowCell类:
[Serializable]
public class DataGridViewTopRowCell
{
/// <summary>
/// 显示文本
/// </summary>
private string _text;
/// <summary>
/// 显示文本
/// </summary>
public string Text
{
get
{
return this._text;
}
set
{
this._text = value;
}
}
/// <summary>
/// 列跨度
/// </summary>
private int _colSpan;
/// <summary>
/// 列跨度
/// </summary>
public int ColSpan
{
get
{
return this._colSpan;
}
set
{
this._colSpan = value;
}
}
/// <summary>
/// 显示宽度
/// </summary>
private int _spanRowWidth;
/// <summary>
/// 显示宽度
/// </summary>
public int SpanRowWidth
{
get
{
return this._spanRowWidth;
}
private set
{
this._spanRowWidth = value;
}
}
private int _relateIndex;
public int RelateIndex
{
get
{
return this._relateIndex;
}
set
{
this._relateIndex = value;
}
}
}
2、DataGridViewEx类:
/// <summary>
/// 复合DataGridView
/// </summary>
public sealed partial class DataGridViewEx : DataGridView
{
/// <summary>
/// 合并列的索引
/// </summary>
private List<int> _mergingColumnsIndex = new List<int>();
/// <summary>
/// 合并列的索引,从0开始
/// </summary>
[Description("合并列的索引,从0开始")]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public List<int> MergingColumnsIndex
{
get
{
return this._mergingColumnsIndex;
}
}
private List<DataGridViewTopRowCell> _cell = new List<DataGridViewTopRowCell>();
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]
public List<WindowsFormsApplication1.DataGridViewTopRowCell> Cells
{
get
{
return this._cell;
}
set
{
this._cell = value;
}
}
}
总结:
1、如果集合是系统定义的类型,如int,string的集合,通过集合编辑器添加是没问题的;
2、如果集合是自定义的类型,如上面的DataGridViewTopRowCell那就存在问题;
有没有解决办法???有碰到过的请及时联系。邮箱:1051573215@qq.com