Modifications to DataGridView aren't reflected in Rows[]

S

Sean Aitken

Good morning,

I'm trying to update a DataSet based on data that has been modified in
a DataGridView. The DataSet isn't binded to the DataGridView because of
a couple conversions. (In this case, a time interval, or TimeSpan, is
stored as number of milliseconds). I haven't found an elegant way to
use the DataSource feature of the DataGridView and allow the
millisecond timespan representation to be displayed as a user-friendly
TimeSpan. To handle this disconnection, I'm simply creating a
DataTable that contains the data the way I want things to appear in the
DataGridView. This works well.

My problem is when I want to save the changes back to the database.
After the user makes a change to a cell and hits 'enter', the "New" row
below is highlighted (indicating that the change was performed on the
cell / row in question). Programatically, I read in the values from the
DataGridView.Rows[] collection. The values I find are the original
values from before the changes were made.

Is there some magic property I'm missing or certain way to get the
modified rows of a DataGridView? I have found nothing in the
documentation that sheds any insight. Should I just hold a reference to
a DataTable locally, bind THAT to the DataGridView, then just look at
the table for changes? Why aren't the Rows[] giving me my changes?

Thanks in a advance!
-Sean
 
S

Sean Aitken

Found my problem. I had two instances of the DataGridView in the
context I was working. I had a property exposing the one I thought I
was working with. Turns out, it was the wrong one. ooops.

Working as designed! The Value property does in fact give me the new
value.

Cheers!
-Sean
 
R

RobinS

Congrats! By the way, you can capture the Format and Parse events
on the cells of the datagrid for that field you want special formatting
on.
These events sit between pulling the data from the data source and
outputting the data into the grid cell. So in one direction, you can
take the number and format it; in the other direction, you can unformat
it and store it.

Robin S.
-----------------------------
Sean Aitken said:
Found my problem. I had two instances of the DataGridView in the
context I was working. I had a property exposing the one I thought I
was working with. Turns out, it was the wrong one. ooops.

Working as designed! The Value property does in fact give me the new
value.

Cheers!
-Sean

Good morning,

I'm trying to update a DataSet based on data that has been modified
in
a DataGridView. The DataSet isn't binded to the DataGridView because
of
a couple conversions. (In this case, a time interval, or TimeSpan, is
stored as number of milliseconds). I haven't found an elegant way to
use the DataSource feature of the DataGridView and allow the
millisecond timespan representation to be displayed as a
user-friendly
TimeSpan. To handle this disconnection, I'm simply creating a
DataTable that contains the data the way I want things to appear in
the
DataGridView. This works well.

My problem is when I want to save the changes back to the database.
After the user makes a change to a cell and hits 'enter', the "New"
row
below is highlighted (indicating that the change was performed on the
cell / row in question). Programatically, I read in the values from
the
DataGridView.Rows[] collection. The values I find are the original
values from before the changes were made.

Is there some magic property I'm missing or certain way to get the
modified rows of a DataGridView? I have found nothing in the
documentation that sheds any insight. Should I just hold a reference
to
a DataTable locally, bind THAT to the DataGridView, then just look at
the table for changes? Why aren't the Rows[] giving me my changes?

Thanks in a advance!
-Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top