简体   繁体   中英

When refreshing the contents of DataGridView, it's not remembering the DataGridViewCheckBox if clicked - C#

Basically, when I add a new task to my List and display it, it works fine and this is the code I used to add a new task and display the set of tasks:

Add task code on 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 is just a public static bool that I was trying to use to get the value selected via the user in the DataGridViewCheckBoxCell for each task, but this did not work using

testerrr = Convert.ToBoolean(((tasksViewerDGV.Rows[i].Cells["taskCompleted"] as DataGridViewCheckBoxCell).Value));

Display task code on 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;

Basically if the user marks the task as completed, I want that value to stay to that particular task eg True. However, when I refresh the DataGridView, the 'ticked' values just get changed back to false (Unticked). Is there anyway that when I click the checkbox for that task to make it stay checked when I refresh?

Kieran

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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