求助:DataGridView添加列时CellType属性为空的异常

flankerfc 2007-05-15 03:48:07
根据网上片贴子 http://paulstovell.net/blog/index.php/custom-drawn-datagridview-cells-with-gdi/
想在DataGridVIew中显示一个百分比的图片

ProgressColumn 是继承自 DataGridViewColumn

不通过设计器 在程序中添加如下代码

ProgressColumn pc = new ProgressColumn();
pc.Name = "percent";
pc.HeaderText = "百分比";
dataGridView1.Columns.Add(pc);

运行到最后一行出错,提示:无法添加该列,原因是它的 CellType 属性为空
请问如何设置?谢谢!
...全文
1069 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
flankerfc 2007-05-15
  • 打赏
  • 举报
回复
谢谢啦!加分!
wzd24 2007-05-15
  • 打赏
  • 举报
回复
public override DataGridViewCell CellTemplate
你要重写这个属性。
如:(这是从DataGridViewTextBoxColumn类取出来的)
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if ((value != null) && !(value is DataGridViewTextBoxCell))
{
throw new InvalidCastException(SR.GetString("DataGridViewTypeColumn_WrongCellTemplateType", new object[] { "System.Windows.Forms.DataGridViewTextBoxCell" }));
}
base.CellTemplate = value;
}
}
flankerfc 2007-05-15
  • 打赏
  • 举报
回复
怎么设置啊?那个CellType不是只读的吗?
wshuangminlg 2007-05-15
  • 打赏
  • 举报
回复
设置他的CellType 属性

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧