Hi folks,
I'm trying to enabled editing for a number of columns in my DataGridView. Now, before anyone suggestions I should read the MSDN article: How to: Specify the Edit Mode for the Windows Forms DataGridView Control, I already have.
In summary (and I quote):
- The underlying data source supports editing.
- The DataGridView control is enabled.
- The EditMode property value is not EditProgrammatically.
- The ReadOnly properties of the cell, row, column, and control are all set to false.
All of that is simple and common sense. I've confirmed that the Enabled = true
. I've confirmed that the EditMode
is EditOnKeystrokeOrF2
I've confirmed that all the columns (except one) are ReadOnly = false
.
What I find interesting is the first line:-
The underlying data source supports editing.
Now, what I'm doing is the following, to bind the data to the DGV :-
// Grab all the Foos.
var foos = (from x in MyRepository.Find()
select new
{
x.Foo1,
x.Foo2,
...
x.FooN
}).ToList();
// Now lets bind this result to the GridView.
dataGridView2.DataSource = foos;
Which I thought was the right way to do things..
What i was planing on doing was, when the cell is changed and the user then leaves the cell, that's where I was planning on grabbing the data that was just changed (figure this out manually) and then manually update the DB.
Is this the right way to do things?