【发布时间】:2009-08-03 19:25:20
【问题描述】:
我将泛型与 ListView 控件一起使用,其初始类定义如下所示:
namespace BaseControlLibrary
{
public partial class CustomListView<T> : System.Windows.Forms.ListView
{
// Custom fields, properties, methods go here
public CustomListView(List<T> data)
{
_columnInfo = new Dictionary<int, string>();
_columnIndex = 0;
_lvwItemComparer = new ListViewItemComparer();
this.ListViewItemSorter = _lvwItemComparer;
InitializeColumnNames();
BindDataToListView(data);
this.Invalidate();
}
}
}
这是我的设计师文件:
partial class CustomListView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
//protected override void Dispose(bool disposing)
//{
// if (disposing && (components != null))
// {
// components.Dispose();
// }
// base.Dispose(disposing);
//}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
我想做的是创建一个Windows控件库,我已经成功地做到了,但是当我无法将DLL添加到工具箱时就会出现问题。我不完全确定为什么我不能这样做。我认为所有 Windows 窗体控件都实现了 IComponent 接口,这是将项目添加到工具箱的要求。是因为类定义中有类型参数吗?
【问题讨论】:
-
也许缺少公共无参数构造函数?
标签: c# generics listview controls