我在一个自定义控件中有一个Collection属性DataKeys,其中DataKey有一项子属性的类型是枚举,但在设计时的状态下,我每次加了一个DataKey,退出后的值却没有反映到控件的代码中,再进行设置的时候,DataKeys中的值又清空了,哪位大哥能帮一下我呢?下面是代码:
DataKey.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace TTools.TWebControls 
{
    //[TypeConverter(typeof(DataKey.TDataKeyConverter))]
    [ToolboxItem(false)]
    [Serializable]
    public class DataKey : System.Web.UI.Control
{
        string _keyName;
string _keyValue;
        DataKeyTypeEnum _keyType = DataKeyTypeEnum.String;
public string KeyName
{
get
{
return (_keyName);
}
set
{
_keyName = value;
}
}

public string KeyValue
{
get
{
return (_keyValue);
}
set
{
_keyValue = value;
}
}        public DataKeyTypeEnum KeyType
{
get { return _keyType; }
set { _keyType = value; }
} public DataKey() : this(null, null,DataKeyTypeEnum.String)
{ } public DataKey(string keyName) : this(keyName, null)
{ }        public DataKey(string keyName, string keyValue)
            : this(keyName, keyValue, DataKeyTypeEnum.String)
{

}
public DataKey(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
this._keyName = keyName;
this.KeyValue = keyValue;
this._keyType = keyType;
}
}
}
DataKeyCollection.csusing System;
using System.Collections;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;namespace TTools.TWebControls
{
    [Serializable]
public class DataKeyCollection : System.Collections.CollectionBase, IEnumerable
{
public DataKeyCollection()
{
//ArrayList();
}
        public DataKeyCollection(ArrayList al)
{
for(int i=0;i<al.Count;i++)
{
                InnerList.Add((DataKey)al[i]);
}
        }
        #region Methods
        public int Add(object value)
        {
            Add((DataKey)value);
            return Count - 1;
        }
public DataKey Add(DataKey _dataKey)
{
            InnerList.Add(_dataKey);
return _dataKey;
} public DataKey Add(string keyName)
{
DataKey _dataKey = new DataKey(keyName);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue)
{
DataKey _dataKey = new DataKey(keyName, keyValue);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
DataKey _dataKey = new DataKey(keyName, keyValue, keyType);
return Add(_dataKey);
}

     public bool Contains(object value)
{
return (-1 != this.IndexOf(value));
}
 
public bool Contains(string keyName)
{
return (-1 != this.IndexOf(keyName));
} public int IndexOf(DataKey item)
{
return InnerList.IndexOf(item);
}
public int IndexOf(object value)
{
if (value != null)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (value == this.InnerList[num2])
{
return num2;
}
}
}
}
return -1;
}
public int IndexOf(string keyName)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (CultureInfo.CurrentCulture.CompareInfo.Compare(keyName, ((DataKey) this.InnerList[num2]).KeyName, CompareOptions.IgnoreWidth | (CompareOptions.IgnoreKanaType | CompareOptions.IgnoreCase)) == 0)
{
return num2;
}
}
}
return -1;
}
 
public void Remove(object value)
{
int num1 = this.IndexOf(value);
if (num1 >= 0)
{
this.RemoveAt(num1);
}
}    
     private void Replace(int index, object newValue)
{
this.InnerList[index] = newValue;
}
#endregion
#region 属性
public DataKey this[int index]
{
get
{
return (DataKey)InnerList[index];
}
set
{
Replace(index, value);
}
}
#endregion
}
}