简体   繁体   English

如何更新dataGridView中的Checkbox值?

[英]How to update Checkbox value in dataGridView?

I have a SQL Server database that contains a bit column and whenever a checkbox is clicked I want to update the bit column with the current value. 我有一个包含bit的SQL Server数据库,每当单击复选框时,我都想用当前值更新位列。

In my C# program I create an event when click on dataGridView to update data 在我的C#程序中,单击dataGridView更新数据时会创建一个事件

TXT_COURSE_ID.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
TXT_COURSE_name.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
TXT_COURSE_TERM.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();

// HERE IS THE PROBLEM: 
CHECK_LAB.CheckState = dataGridView1.CurrentRow.Cells[3].Value.ToString();

The problem is that you need to look at the type of CheckState property and what you trying to set it to. 问题是您需要查看CheckState属性的类型以及您要设置的类型。 CheckState enum is not the same as string. CheckState枚举与字符串不同。

You should do something like this: 您应该执行以下操作:

CHECK_LAB.Checked = bool.Parse(dataGridView1.CurrentRow.Cells[3].Value.ToString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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