Ewan Walker asked 2019-01-29 08:44:19 UTC
I have tried to work out how to add a custom column to a data grid view
It seems to have something to do with setting the control as the custom control
dgvOfficeStaff.Columns[0].CellTemplate.Control = mccStaff;
You then seem to need to have to add the control to each Cell;
private void dgvOfficeStaff_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Value != null)
{
if(dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control == null) dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control = mccStaff;
((MultiColumnComboBox)dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control).BoundValue = dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Value;
}
}
However this code does not work.
What is the correct way to add a custom control column?
Thanks for your help
Ewan
Ewan Walker asked 2019-01-29 08:44:19 UTC
I have tried to work out how to add a custom column to a data grid view
It seems to have something to do with setting the control as the custom control
dgvOfficeStaff.Columns[0].CellTemplate.Control = mccStaff;
You then seem to need to have to add the control to each Cell;
private void dgvOfficeStaff_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0 && dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Value != null)
{
if(dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control == null) dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control = mccStaff;
((MultiColumnComboBox)dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Control).BoundValue = dgvOfficeStaff[e.ColumnIndex, e.RowIndex].Value;
}
}
However this code does not work.
What is the correct way to add a custom control column?
Thanks for your help
Ewan