5

I have a list of Record objects that serve as rows in my DataGridView. Each Record has a new bool value Helped. Sure enough, this new value shows up as check mark in my form.

As it stands currently, when this box is checked it doesn't seem to change the value of Helped bool in the corresponding Record.

Is there some sort of read-only property I need to change? How do I pass a click on my form back as a change in value of its DataSource?

Edit: I've found the System.Windows.Forms.DataGridViewEditMode.EditOnEnter property, but I'm still not seeing my Record.Helped property get updated.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
MrDysprosium
  • 489
  • 9
  • 20
  • this is very very simple actually if you create a public instance of a datatable then when you change the value of a field from True to False, then Cast the DataGridView.DataSource as a DataTable do a google search on examples on how to Cast DataGridView as a DataTable – MethodMan Oct 31 '16 at 18:09
  • I'm trying to wrap my head around what you said, but I'm not sure I understand. My DataGridView already properly displays everything in my `DataSource` (which is a `SortableBindingList`). I just want to check for rows that have that checkbox marked and update the corresponding `Record` objects. – MrDysprosium Oct 31 '16 at 18:15

1 Answers1

8

As it stands currently, when this box is checked it doesn't seem to change the value of Helped bool in the corresponding Record.

The changes which you make on a cell of DataGridView, doesn't commit immediately to the data source until you finish editing the cell, then changes will be pushed to data source. If for any reason you want to push changes sooner, you can call:

dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

For example you can do that in CellContentClick event of your DataGridView to push check box value to the underlying property of data source.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398