2

I'm attempting to create a custom control from dataGridView which includes a checkboxcolumn. I have added the code to produce this and added the newly created checkBoxDataGridView onto my form in a new project.

I have 2 problems:

1. The column gets added a 2nd time when I open and close the form that holds the new checkBoxDataGridView in designtime. You will see in my code I have tried multiple checks, now commented out, so it does not add the column during design time a 2nd time or more than once. Also only needs to add it during designtime, which I guess is no problem if I check whether its been added already.

2. The checkbox column does not instantiate the name I gave it in the controls class. eg.: col.Name = "dgvTickCol"

    public class CheckBoxDataGridView : DataGridView
    {          
        public CheckBoxDataGridView()
        {          
            AddCheckColumn();
        }

        private void AddCheckColumn()
        {
            //if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)                
            //if (!Columns.Contains("dgvTickCol"))                
            //if (this.Rows[0].Cells["dgvTickCol"].Value != null)
            //if (this.Rows[0].Cells["dgvTickCol"].ColumnIndex == -1)
            //{
                DataGridViewColumn col = new DataGridViewCheckBoxColumn();            
                col.Name = "dgvTickCol";
                col.HeaderText = "";
                col.SortMode = DataGridViewColumnSortMode.NotSortable;
                Columns.Add(col);            
            // }

    }
}
13
  • I have had a similar problem. Are you implementing the custom control as referenced dll, or as a new item on your working project? Commented Jun 8, 2017 at 14:49
  • I have it in separate project(assuming DLL) with a few custom controls and user controls in it, which I use in different desktop applications to speed up coding. Any of those controls I add off the toolbox on the left of the screen onto a form. Commented Jun 8, 2017 at 15:01
  • Someone recommended clearing the container before adding the column. Not sure how or where. Still investigating. Will let you know if it works. Commented Jun 8, 2017 at 15:04
  • I my similar question about this problem, someone suggested me this article to read about it, but I didn't solvet. I noticed that on designer of the user control/windows form which I was implementing, the result wasn't as I expected, you can have a look on yours. Commented Jun 8, 2017 at 15:22
  • Why would you need to create a “Custom” DataGridView to simply add a DataGridViewCheckBoxColumn??? Simply create a new DataGridView, add a DataGridViewCheckBoxColumn and that is all you need to do… there is no need for this “Custom` “Class” as you have it currently posted. What is this “Custom” DataGridView supposed to do that a regular DataGridView can’t already do? Commented Jun 8, 2017 at 21:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.