TreeView 數據綁定到List<T>
有數據集合List<T>TreeView 數據綁定到List<T>
--------------------编程问答-------------------- 他们的数据结构就不一个。
如果一定要实现的话
T 本身也至少包含一个 List<T>属性
--------------------编程问答-------------------- 学习中~~
友情UP --------------------编程问答-------------------- --------------------编程问答-------------------- 是不是要实现一个控件的 强类型集合 属性? 如果是, 下面是一个参考的例子:
/// <summary>
/// 工具按钮集合类
/// </summary>
[ToolboxItem(false)]
[ParseChildren(true)]
[Editor(typeof(CommandCollectionEditor), typeof(UITypeEditor))]
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public class CommandCollection : Collection<ItemBase>
{
#region 定义构造函数
public CommandCollection()
: base()
{
}
#endregion
/// <summary>
/// 得到集合元素的个数
/// </summary>
public new int Count
{
get
{
return base.Count;
}
}
/// <summary>
/// 表示集合是否为只读
/// </summary>
public bool IsReadOnly
{
get
{
return false;
}
}
/// <summary>
/// 添加对象到集合
/// </summary>
/// <param name="item"></param>
public new void Add(ItemBase item)
{
base.Add(item);
}
/// <summary>
/// 清空集合
/// </summary>
public new void Clear()
{
base.Clear();
}
/// <summary>
/// 判断集合中是否包含元素
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public new bool Contains(ItemBase item)
{
return base.Contains(item);
}
/// <summary>
/// 移除一个对象
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public new bool Remove(ItemBase item)
{
return base.Remove(item);
}
/// <summary>
/// 设置或取得索引项
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public new ItemBase this[int index]
{
get
{
return base[index];
}
set
{
base[index] = value;
}
}
}
在主控件中应用:
[DefaultProperty("ToolBarItems")]
[ToolboxData("<{0}:MultiTypeCollectionEditorControl runat=server></{0}: MultiTypeCollectionEditorControl>")]
[ParseChildren(true, "ToolBarItems")]
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public class MultiTypeCollectionEditorControl : WebControl
{
private CommandCollection _ToolBarItems = new CommandCollection();
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility. Content)]
[Description("工具工具按钮集设置")]
[Category("集合设置")]
public CommandCollection ToolBarItems
{
get
{
if (_ToolBarItems == null)
{
_ToolBarItems = new CommandCollection();
}
return _ToolBarItems;
}
}
//....
}
这章的完整内容及示例如下(大概在08年12月底会整理完并放到如下链接中):
http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
补充:.NET技术 , 组件/控件开发