刷新 DataGridView 的内容时,如果单击它不会记住 DataGridViewCheckBox - C#
When refreshing the contents of DataGridView, it's not remembering the DataGridViewCheckBox if clicked - C#
基本上,当我向列表中添加新任务并显示它时,它工作正常,这是我用来添加新任务并显示任务集的代码:
在addTask.cs上添加任务代码:
taskStructure.TasksArray.Add(new taskStructure
{
taskID = taskIDValueTxt.Text,
taskName = taskNameRTB.Text,
taskDescription = taskDescRTB.Text,
taskPriority = checkedButton,
taskDateAndTimeCompletion = finishDateAndTimeDTP.Text,
taskCompleted = mainPage.testerrr
});
testerrr 只是我试图用来获取的 public 静态布尔值
通过用户在 DataGridViewCheckBoxCell 中为每个任务选择的值,但这在使用
时不起作用
testerrr = Convert.ToBoolean(((tasksViewerDGV.Rows[i].Cells["taskCompleted"] as DataGridViewCheckBoxCell).Value));
在 mainPage.cs
上显示任务代码
//Change it from null to the List<T> so the DataGridView can update itself with the new and current task values
taskStructureBindingSource.DataSource = null;
taskStructureBindingSource.DataSource = taskStructure.TasksArray;
基本上,如果用户将任务标记为已完成,我希望该值保留在该特定任务中,例如 True。但是,当我刷新 DataGridView 时,'ticked' 值会变回 false(未勾选)。无论如何,当我单击该任务的复选框以使其在刷新时保持选中状态?
基兰
将 DataGridViewCheckBoxColumn 的 DataProperty 设置为 "taskCompleted" 以将此列的值绑定到 taskStructure 对象的 taskCompleted 属性。
基本上,当我向列表中添加新任务并显示它时,它工作正常,这是我用来添加新任务并显示任务集的代码:
在addTask.cs上添加任务代码:
taskStructure.TasksArray.Add(new taskStructure
{
taskID = taskIDValueTxt.Text,
taskName = taskNameRTB.Text,
taskDescription = taskDescRTB.Text,
taskPriority = checkedButton,
taskDateAndTimeCompletion = finishDateAndTimeDTP.Text,
taskCompleted = mainPage.testerrr
});
testerrr 只是我试图用来获取的 public 静态布尔值 通过用户在 DataGridViewCheckBoxCell 中为每个任务选择的值,但这在使用
时不起作用testerrr = Convert.ToBoolean(((tasksViewerDGV.Rows[i].Cells["taskCompleted"] as DataGridViewCheckBoxCell).Value));
在 mainPage.cs
上显示任务代码 //Change it from null to the List<T> so the DataGridView can update itself with the new and current task values
taskStructureBindingSource.DataSource = null;
taskStructureBindingSource.DataSource = taskStructure.TasksArray;
基本上,如果用户将任务标记为已完成,我希望该值保留在该特定任务中,例如 True。但是,当我刷新 DataGridView 时,'ticked' 值会变回 false(未勾选)。无论如何,当我单击该任务的复选框以使其在刷新时保持选中状态?
基兰
将 DataGridViewCheckBoxColumn 的 DataProperty 设置为 "taskCompleted" 以将此列的值绑定到 taskStructure 对象的 taskCompleted 属性。