Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:23:25+00:00 2026-06-17T08:23:25+00:00

I have a custom control in a DataGridView cell. Its a combobox that contains

  • 0

I have a custom control in a DataGridView cell. Its a combobox that contains checkbox items (CheckBoxComboBox). Here’s the issue :
1. Enter one of the CheckBoxComboBoxes and select off some checkbox items. The Text of the CheckboxComboBox is a csv string of the checked items.
2. Click a different CheckboxComboBox cell that is emtpy (no checked items)

Result : The text of the new cell contains the text of the old cell. If I click a CheckBoxComboBox cell, then a non-CheckBoxComboBox cell and then a CheckBoxComboBox cell, it works correctly.

I have read and implemented the custom DataGridViewCell based on this document :
How to: Host Controls in Windows Forms DataGridView Cells

When I debug through my custom DataGridViewEditingControl, it appears that the EditingControl.Tag isn’t updated.

So I am assuming that I have an issue with the EditingControl is being reused.

Things I have tried :

1. Override DataGridViewCell.Clone()

    public override object Clone()
    {
        DataGridViewCheckBoxComboBoxCell checkBoxComboBoxCell = base.Clone() as DataGridViewCheckBoxComboBoxCell;
        if (checkBoxComboBoxCell != null)
        {
            checkBoxComboBoxCell.Tag = this.Tag;
            checkBoxComboBoxCell.Values = this.Values;


        }
        return checkBoxComboBoxCell; 
    }

2. Override DataGridViewCell.DetachEditingControl()

public override void DetachEditingControl()
    {
        DataGridView dataGridView = this.DataGridView;

        if (dataGridView == null || dataGridView.EditingControl == null)
        {
            throw new InvalidOperationException("Cell is detached or its grid has no editing control.");
        }

        DataGridViewCheckBoxComboBoxCellEditingControl ctl = DataGridView.EditingControl as DataGridViewCheckBoxComboBoxCellEditingControl;
        if (ctl != null)
        {
            //Just trying different things
            ctl.EditingControlFormattedValue = String.Empty;
            ctl.Text = string.Empty;
            ctl.Tag = null;
            ctl.Items.Clear();
        }

        base.DetachEditingControl();
    }

Any idea how to resolve this issue ? Thanks.

EDIT 1

Here is the DataGridViewCheckBoxComboBoxColumn class

class DataGridViewCheckBoxComboBoxColumn : DataGridViewColumn
{
     public override object Clone()
    {
        DataGridViewCheckBoxComboBoxColumn that = (DataGridViewCheckBoxComboBoxColumn)base.Clone();

        return that;
    }

    private DataGridViewCheckBoxComboBoxCell _cell = null;
    public DataGridViewCheckBoxComboBoxColumn()
    {
        _cell = new DataGridViewCheckBoxComboBoxCell();
        base.CellTemplate = _cell;
    }

    public override DataGridViewCell CellTemplate
    {
        get
        {
            return base.CellTemplate;
        }
        set
        {
            // Ensure that the cell used for the template is a DateCell.
            if (value != null &&
                !value.GetType().IsAssignableFrom(typeof(DataGridViewCheckBoxComboBoxCell)))
            {
                throw new InvalidCastException("Must be a DataGridViewCheckBoxComboBoxColumn");
            }
            base.CellTemplate = value;
        }
    }

    public string Values
    {
        set
        {
            _cell.Tag = value;
            this.Tag = value;
        }
        get
        {
            return _cell.Tag.ToString();
        }
    }
}

EDIT 2
My DataGridViewCheckBoxComboBoxCell overrides Paint(). When I put a breakpoint on this method, it gets called twice when I click the cell. The first time its called, the formattedValue is empty. However, the second time, the formattedValue contains the incorrect string of the previous checkboxcombobox cell.

protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                  DataGridViewElementStates cellState, object value, object formattedValue,
                                  string errorText, DataGridViewCellStyle cellStyle,
                                  DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                  DataGridViewPaintParts paintParts)
    {}

Why does it get called twice and why on the second call does it contain the wrong formatted value for the correct cell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:23:26+00:00Added an answer on June 17, 2026 at 8:23 am

    Figured it out. The issue was that in the DetachEditingControl() I needed to clear the CheckBoxItems.

    public override void DetachEditingControl()
        {
            DataGridView dataGridView = this.DataGridView;
    
            if (dataGridView == null || dataGridView.EditingControl == null)
            {
                throw new InvalidOperationException("Cell is detached or its grid has no editing control.");
            }
    
            DataGridViewCheckBoxComboBoxCellEditingControl ctl = DataGridView.EditingControl as DataGridViewCheckBoxComboBoxCellEditingControl;
            if (ctl != null)
            {
                ctl.CheckBoxItems.Clear();  //Forgot to do this.
                ctl.EditingControlFormattedValue = String.Empty;
            }
    
            base.DetachEditingControl();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Custom Control that has multiple textbox fields and a checkbox contained
I have a custom DataGridViewCell with a user-control as its editing control. The cell
I have custom control - using Win Forms, that contains four TextBoxes, all have
I have a custom DataGridView column that uses an embedded control that pops up
I have custom server control contains templatefield when an out button clicked the field
I have a custom control that inherits from UserControl , and I can't get
I have a custom control that needs a minor adjustment when running on XP
I have a custom control that displays a tryAgain button when the control is
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I'm working on creating a custom winforms datagridview control that inherits the built in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.