简体   繁体   中英

When I want to check all DataGridview checkbox column I got Error Datatable not binding to Datagridview

When I want to check all DataGridview checkbox column I got Error Datatable not binding to Datagridview.

    private void ChSelAll_CheckedChanged(object sender, EventArgs e)
            {
                foreach (DataRow dr in DTDetail.Rows)
                   dr["Selection"] = ChSelAll.Checked;
                
           }

And wia follow code I binding datasource to datagridview:

     private void FrmShowSendProduct_Load(object sender, EventArgs e)
        {
            DgvSubSend.DataSource = null;
            BaseComboFill();
            if(PageKind == 1)
            {
            }
            if (PageKind == 2 || PageKind == 3)
            {
                colSelection.Visible = false;
                btnSave.Visible = false;
                rball.Visible = true;
                rbremain.Visible = true;
                rbremainnot.Visible = true;
                if (PageKind == 3)
                {
                    dt = _sendOrder.ShowAcceptedSendProductForProduct(MisLib.Classes.MainLib.ActiveYear.ToString(), codeproduct, ReqDateFromTemp, ReqDateToTemp);
                    DgvSend.AutoGenerateColumns = false;
                    bs.DataSource = dt;
                    DgvSend.DataSource = bs;   
                }
            }        
        }

Try follow:

foreach (DataGridViewRow row in YourDataGridView.Rows)
            {
                row.Cells["yourColumnName"].Value = true;
                YourDataGridView.EndEdit();
            }

be careful about YourDataGridView.EndEdit(); if you don't use EndEdit() your changes wont accept.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM