自定义DataGridViewColumn - 在鼠标双击之前,单元格未被绘制(可见)

时间:2012-08-12 14:03:35

标签: c# .net datagridview datagridviewcolumn

我需要为datagridview构建一个自定义DataGridViewColumn,以便...想象下面的场景(骨架):

public class CustomColumn : DataGridViewColumn
{
        public CustomColumn(PropertyEditor propertyEditor)
            : base(new CustomCell(propertyEditor))
        {            
        }

        (...)
}

class CustomCell : DataGridViewTextBoxCell
{
        public PropertyEditor propertyEditor = null;

        public CustomCell() : base()
        {                
        }

        public CustomCell(PropertyEditor propertyEditor)
            : this()
        {                
            this.propertyEditor = propertyEditor;
        }

        (...)

        public override object DefaultNewRowValue
        {
            get
            {
                return this.propertyEditor.Source;
            }
        }          

        (...) 
}

class CustomEditingControl : PropertyEditor, IDataGridViewEditingControl
{
        (...)
}

* PropertyEditor是National Instruments组件。这是细胞的内容。

所以我以编程方式创建一个列,然后添加:

PropertyEditor propertyEditor = new PropertyEditor();
propertyEditor.Source = new PropertyEditorSource(new ScatterPlot(), "LineStep");
propertyEditor.SourceValue = "XYStep"; // Default value for property LineStep

PropertyEditorColumn col = new PropertyEditorColumn(propertyEditor);
this.dataGridView1.Columns.Add(col);

我的问题是在DefaultNewRowValue中,this.propertyEditor为null而不是参数传递,因为在添加列后会自动调用不带参数的CustomCell构造函数。我想用默认值初始化单元格,并将其作为参数传递。我怎样才能做到这一点?

THX。

0 个答案:

没有答案