首页 新闻 会员 周边

datagridview 的 checkbox 无法勾选

0
悬赏园豆:10 [已解决问题] 解决于 2019-01-30 15:04

鼠标点击datagridview上的checkbox 没反应。请问是怎么回事呢?
我的代码如下:

public void DtToView(DataTable calldt)
{
dataGridViewX1.Rows.Clear();
dataGridViewX1.Columns.Clear();
dataGridViewX1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
dataGridViewX1.ReadOnly = true;
dataGridViewX1.ColumnCount = 5;
dataGridViewX1.ColumnHeadersVisible = true;

        // Set the column header style.
        DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

        columnHeaderStyle.BackColor = Color.DarkSlateGray;
        columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Regular);
        dataGridViewX1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

        //datagridview上新建添加的checkbox控件
        DataGridViewCheckBoxColumn ck = new DataGridViewCheckBoxColumn();
        //ck.TrueValue = true;
        //ck.FalseValue = false;
        dataGridViewX1.Columns.Insert(0, ck);
        // Set the column header names.
        dataGridViewX1.Columns[0].Name = "选择";
        dataGridViewX1.Columns[1].Name = "id";
        dataGridViewX1.Columns[2].Name = "callid";
        dataGridViewX1.Columns[3].Name = "姓名";
        dataGridViewX1.Columns[4].Name = "电话";
        dataGridViewX1.Columns[5].Name = "状态";

        dataGridViewX1.Columns[0].Width = 45;
        dataGridViewX1.Columns[1].Visible = false;
        dataGridViewX1.Columns[2].Visible = false;
        dataGridViewX1.Columns[3].Width = 75;
        dataGridViewX1.Columns[4].Width = 100;
        dataGridViewX1.Columns[5].Width = 65;
        dataGridViewX1.RowsDefaultCellStyle.Font = new Font("宋体", 10, FontStyle.Regular);
        for (int i = 0; i < calldt.Rows.Count; i++)
        {
            int index = this.dataGridViewX1.Rows.Add();
            this.dataGridViewX1.Rows[index].Cells[1].Value = calldt.Rows[i][0].ToString();
            this.dataGridViewX1.Rows[index].Cells[2].Value = calldt.Rows[i][1].ToString();
            this.dataGridViewX1.Rows[index].Cells[3].Value = calldt.Rows[i][2].ToString();
            this.dataGridViewX1.Rows[index].Cells[4].Value = calldt.Rows[i][3].ToString();
            string status = calldt.Rows[i][4].ToString();
            if (int.Parse(status) == 1)
            {
                //dataGridViewX1.Columns[0].ReadOnly = false; 
                this.dataGridViewX1.Rows[index].Cells[5].Value = "已分发";
            }
            else if (int.Parse(status) == 0)
            {
                //dataGridViewX1.Columns[0].ReadOnly = false;
                this.dataGridViewX1.Rows[index].Cells[5].Value = "未分发";
            }
        }
    }
恶之必要的主页 恶之必要 | 初学一级 | 园豆:165
提问于:2019-01-30 14:31
< >
分享
最佳答案
1

看来你的问题很多,因为你设置了只读,所以无法选中,这种情况只能针对每一列设置只读,这样才可以

收获园豆:10
jqw2009 | 老鸟四级 |园豆:2439 | 2019-01-30 14:36

我也是在摸索着做,毕竟对于winform是个新手,谢谢你,方便要个你的联系方式吗?可以请教你,不方便也没关系。

恶之必要 | 园豆:165 (初学一级) | 2019-01-30 14:59

@恶之必要: 你是女生吗?

jqw2009 | 园豆:2439 (老鸟四级) | 2019-01-30 15:49

@jqw2009: 对呀

恶之必要 | 园豆:165 (初学一级) | 2019-01-30 17:32

@恶之必要: 15995685610 加微信吧

jqw2009 | 园豆:2439 (老鸟四级) | 2019-01-31 09:01
其他回答(1)
0

我设置了ReadOnly = false还是多选框勾选不上,请问再怎么设置呢

CuiJie0605 | 园豆:202 (菜鸟二级) | 2023-07-12 16:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册