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