How do I to change the property value for custom DataGridViewComboBoxCell

  • Thread starter Thread starter Badruddin Koronfol
  • Start date Start date
B

Badruddin Koronfol

Guest
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.


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

public class MultiColumnComboBox : DataGridViewComboBoxColumn,
INotifyPropertyChanged
{
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;
RaisePropertyChanged("NewItemButtonCaption");
}
get
{
return _NewButtonText;
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(
[System.Runtime.CompilerServices.CallerMemberName]
string caller = "NewItemButtonCaption")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
MCCoboBoxCell.NewItemButtonCaption = NewItemButtonCaption;
this.CellTemplate = MCCoboBoxCell;
}

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
//
...

}
}


1493830.png

Continue reading...
 
Back
Top