根据网上片贴子 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 属性为空
请问如何设置?谢谢!

解决方案 »

  1.   

    怎么设置啊?那个CellType不是只读的吗?
      

  2.   

    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;
            }
        }