集合编辑器属性保存值的问题
我写的个组件,有以下一个属性printRow的属性是我自定义的一个CollectionBase的集合,在用这组件时,设置printRow属性时正确地弹出集合编辑器,可以添加删除编辑,但一确定了再进去却根本没有保存到值,当然在代码里面看的值也是空的。我查了下资料,应该是要“指定特定的设计器序列化策略”,但没找到示例代码,哪位高人帮帮忙
private printCollection _printRow;
[Category( "列设置 "),
Description( "有关打印列的设置 ")]
/// <summary>
/// 有关打印列的设置
/// </summary>
public printCollection printRow
{
get { return _printRow; }
set { _printRow = value; }
}
------解决方案--------------------up
------解决方案--------------------帮LZ顶
------解决方案--------------------首先你要设定PersistenceMode(PersistenceMode.InnerProperty)
也就是
private printCollection _printRow;
[Category( "列设置 "),
Description( "有关打印列的设置 "),
PersistenceMode(PersistenceMode.InnerProperty)]
/// <summary>
/// 有关打印列的设置
/// </summary>
public printCollection printRow
{
get { return _printRow; }
set { _printRow = value; }
}
这样IDE才会把你的printCollection里的值保存下来
如果你是用系统已有的集合,只要添加TypeConverter(typeof(转换器名))就可以了
如果你是自定义的集合属性,还必须定义自已的类型转换类
继承于ExpandableObjectConverter的转换器
以下代码仅共参考:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Drawing.Design;
using System.Web.UI.Design.WebControls;
using System.Collections.Specialized;
using System.Drawing;
using System.Security.Permissions;
using System.Globalization;
using System.ComponentModel.Design;
namespace Wima.Web.UI
{
/// <summary>
/// 边距
/// </summary>
[TypeConverter(typeof(MarginItemConverter))]
public class MarginItem : IStateManager
{
public MarginItem()
{
}
/// <summary>
/// 左边距
/// </summary>
[Category( "Behavior "), Description( "左边距 "), NotifyParentProperty(true)]
public Unit Left
{
get
{
object o = ViewState[ "Left "];
if (o != null)
{
return (Unit)o;
}
return Unit.Parse( "30 ");
}
set
{
ViewState[ "Left "] = value;