dataGridView1 checkbox 列点击单元格选中

            dataGridView1.CellClick += (sender, e) =>
            {
                if (e.ColumnIndex == 0)
                {
                    InvoiceDetail curRow = dataGridView1.Rows[e.RowIndex].DataBoundItem as InvoiceDetail;

                    string mainId = curRow.Id_main;
                    bool isChecked = !curRow.Selected;
                    dataGridView1[e.ColumnIndex, e.RowIndex].Value = isChecked;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (row.DataBoundItem is InvoiceDetail cust)
                        {
                            if (cust.Id_main == mainId)
                            {
                                cust.Selected = isChecked;
                            }
                        }
                    }
                    dataGridView1.EndEdit();
                    dataGridView1.Refresh();
                }
            };

 

posted @ 2025-05-18 21:21  _York  阅读(8)  评论(0)    收藏  举报