【问题标题】:When refreshing the contents of DataGridView, it's not remembering the DataGridViewCheckBox if clicked - C#刷新 DataGridView 的内容时,如果单击它不会记住 DataGridViewCheckBox - C#
【发布时间】:2015-04-25 22:38:33
【问题描述】:

基本上,当我将新任务添加到我的列表并显示它时,它工作正常,这是我用来添加新任务并显示任务集的代码:

在 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 只是我试图用来获取的公共静态布尔值 通过用户在 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 时,“已勾选”的值会变回 false(未勾选)。无论如何,当我单击该任务的复选框以使其在刷新时保持选中状态时?

基兰

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:

    将 DataGridViewCheckBoxColumn 的 DataProperty 设置为“taskCompleted”,以将此列的值绑定到 taskStructure 对象的 taskCompleted 属性。

    【讨论】:

    • 非常感谢,没想到这么简单!答案标记为??
    猜你喜欢
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    • 1970-01-01
    • 2017-07-14
    • 2010-11-24
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多