Click here to Skip to main content
15,917,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one i create check box in gridview on runtime.
But one problem i face i use check box when i checke the check box then datagridview fill with data and automatical create one checkbox in one row.
problem is that
when i uncheck the chekbox then datagrid view datasource is empaty and when i check the check box again then it create two check box with every row inside the grid view....
And when i again uncheck the check box and again checked the check box then it create three check box inside the grid view any one help me how can i stop the multiple check box that created inside the grid view.
-----------------------------------------------------------------------------
I want only one check box with all the rows

I try this code
this code is run when checkbox check sate is changed

What I have tried:

private void isactiveOffercheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (isactiveOffercheckBox.Checked == true)
            {
                OfferdataGridView.DataSource = null;
                OfferdataGridView.DataSource = GetofferfromDb();
                DataGridViewCheckBoxColumn chekbox = new DataGridViewCheckBoxColumn();
                chekbox.HeaderText = "chekbox";
                chekbox.Name = "chekbox";
                OfferdataGridView.Columns.Add(chekbox);               
                OfferdataGridView.Enabled = true;
                OfferdataGridView.Height = 146;               
            }
            else           
            {             
                OfferdataGridView.DataSource = null;
                OfferdataGridView.Enabled = false;                
            }
        }
Posted
Updated 13-Dec-18 6:41am
Comments
F-ES Sitecore 13-Dec-18 11:56am    
Web forms? Win forms? WPF?
Fahid Zahoor 13-Dec-18 13:50pm    
Win forms

1 solution

Here's an example with a DataTable, the DataGridViewCheckBoxColumn is not needed this way:
https://www.c-sharpcorner.com/blogs/adding-check-box-to-datagridview-column-without-using-datagridviewcheckboxcolumn-class1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900