Winforms .NET 3.5 (C#)
我有一个 DataGridView (DGView),并创建了要在 DGView 中显示的 CustomColumn 和 CustomCell。我创建了一个我想在 CustomCell 中显示的 CustomUserControl。
问题:我没有在列中看到用户控件。我想我需要在 CustomCell 中覆盖 Paint() 方法 - 我该怎么做?
注意 - 托管用户控件的 MSDN 示例用于编辑单元格值 - 您可以在其中使您的用户控件在您正在编辑单元格的位置可见。我希望我的用户控件呈现为普通的 winform 控件。此用户控件显示行的通知 .. 并且每行可以有不同的通知。我希望用户能够单击通知并获取有关它的更多详细信息。..但现在我被困在“如何显示这个用户控件”
任何指针将不胜感激。
public class CustomColumn : DataGridViewColumn {
public CustomColumn() : base(new CustomeCell()) { }
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
// Ensure that the cell used for the template is a CalendarCell.
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CustomeCell)))
{
throw new InvalidCastException("It should be a custom Cell");
}
base.CellTemplate = value;
}
}
}
public class CustomeCell : DataGridViewTextBoxCell
{
public CustomeCell() : base() { }
public override Type ValueType
{
get
{
return typeof(CustomUserControl);
}
}
public override Type FormattedValueType
{
get
{
return typeof(CustomUserControl);
}
}
}