DataGridView中复选框的空值 [英] Null value for a checkbox in a DataGridView
问题描述
我有一个DataGridView
,我已经手动将其编码为表格,并且单元格4,5,7,8,9是复选框字段,我需要3个复选框答案,以便在加载DGV时它为空" '',然后用户输入true或false.有没有办法做到这一点?好像我放了除"true"或"false"以外的任何其他内容一样,我得到一个错误,我试图放入不确定",但这仍然引发错误.
Hi,
i have a DataGridView
which i have manually coded into the form, and cells 4,5,7,8,9 are checkbox fields, and i need 3 answers for the checkboxes so that when the DGV is loaded it is ''null'' and then the user inputs true or false. is there a way to do this? as if i put anything other than ''true'' or ''false'' i get an error, i have tried to put ''Indeterminate'' but that still throws an error.
TMSScoreSheet.Rows[0].Cells[4].Value = "Indeterminate";
TMSScoreSheet.Rows[0].Cells[5].Value = "False";
TMSScoreSheet.Rows[0].Cells[7].Value = "False";
TMSScoreSheet.Rows[0].Cells[8].Value = "False";
TMSScoreSheet.Rows[0].Cells[9].Value = "False";
Billy
Billy
推荐答案
你好
在C#中使用Nullable类型
Hello
Use Nullable type in C#
bool? b = null;
参见:
http://msdn.microsoft.com/en-us/library/1t3y8s4s (v = vs.80).aspx [ http://wpf.2000things .com/2011/07/29/353-binding-a-three-state-checkbox-to-a-nullable-bool/ [ http://stackoverflow.com/questions/8401974/what-is-best-way-to-bind-to-tri-state-复选框 [ http://social.msdn.microsoft.com/Forums/zh/winforms/thread/c8fb99ad-d9a8-40dd-9a9d-a1f598a9a92e [
See:
http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.80).aspx[^]
And for your CheckBox, if your application is WPF, try this:
http://wpf.2000things.com/2011/07/29/353-binding-a-three-state-checkbox-to-a-nullable-bool/[^]
If WinForm:
http://stackoverflow.com/questions/8401974/what-is-best-way-to-bind-to-tri-state-checkbox[^]
Or
http://social.msdn.microsoft.com/Forums/en/winforms/thread/c8fb99ad-d9a8-40dd-9a9d-a1f598a9a92e[^]
这篇关于DataGridView中复选框的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!