1

我需要为 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 构造函数。我想用默认值初始化单元格,并将其作为参数传递。我怎样才能做到这一点?

谢谢。

4

0 回答 0