Как изменить значение свойства для пользовательского datagridviewcomboboxcell
Hello Everybody. I developed Multi-column ComboBox and I used the first item in it to use it as a button to add a new item to the ComboBox as needed, I named the linked property NewItemButtonCaption. Till now everything is okay, after that I used that Multi-column CoboBox to create custom DataGridView Column and I cloned the new property in the ComboBoxCell and ComboBoxColumn. The problem is that when I create the Column in a DataGridView the NewItemButtonCaption doesn't work.
Что я уже пробовал:
namespace Custom_DataGridColumn { public class MCCoboBoxCell : DataGridViewComboBoxCell { public override Type EditType => typeof(MCCBEditingControl); public override Type ValueType => base.ValueType; public MCCoboBoxCell() : base() { } public override void InitializeEditingControl( int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { base.InitializeEditingControl( rowIndex, initialFormattedValue, dataGridViewCellStyle); MCCBEditingControl ctl = DataGridView.EditingControl as MCCBEditingControl; ctl.NewButtonText = NewItemButtonCaption; ctl.DropDownStyle = ComboBoxStyle.DropDown; } public override object DefaultNewRowValue => base.DefaultNewRowValue; private string _NewButtonText = string.Empty; [NotifyParentProperty(true)] public string NewItemButtonCaption { get { return _NewButtonText; } set { _NewButtonText = value; } } public override object Clone() { var clone = (MCCoboBoxCell)base.Clone(); clone.NewItemButtonCaption = NewItemButtonCaption; return clone; } } } namespace Custom_DataGridColumn { public class MultiColumnComboBox : DataGridViewComboBoxColumn { MCCoboBoxCell MCCoboBoxCell; public MultiColumnComboBox() { if (MCCoboBoxCell == null) { MCCoboBoxCell = new MCCoboBoxCell(); this.CellTemplate = MCCoboBoxCell; } } private string _NewButtonText = string.Empty; [NotifyParentProperty(true)] public string NewItemButtonCaption { set { _NewButtonText = value; } get { return _NewButtonText; } } public override object Clone() { var clone = (MCCoboBoxCell)base.CellTemplate; clone.NewItemButtonCaption = NewItemButtonCaption; return base.Clone(); } } } class Form1 : Form { private DataGridView dataGridView1; private Custom_DataGridColumn.MultiColumnComboBox Column2; DataTable dataTable = new DataTable("Accounts"); public Form1() { InitializeComponent(); #region DataTable Info } private void InitializeComponent() { this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.Column2 = new Custom_DataGridColumn.MultiColumnComboBox(); // // dataGridView1 // this.dataGridView1.ColumnHeadersHeightSizeMode = this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column2}); ... // // Column2 // this.Column2.HeaderText = "Column2"; this.Column2.Name = "Column2"; this.Column2.NewItemButtonCaption = "Add New Item";\\Not working // // Form1 // ... } }