Skip to content

How do I add a custom control to a data grid view #1994

Description

@itg-assistant

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions