refresh from DataGridView to bound DataSet


R

roybrew

I can easily programmatically add a new row to a DataSet, fill the
columns with the appropriate data and the new row is in the
corresponding DataGridView is conveniently updated when the DataSet
changes. Is there any way to do this in the other direction? That is,
if the DateGridView is enabled to allow the user to add new rows by
typing in the grid, is there some way to "push" this data back to the
bound DataSet so that it stays in sync with the DataGridView. It
doesn't appear to update the underlying database table when I do an
Update on the data adapter.

roy
 
Ad

Advertisements

R

roybrew

Right, but if you make a change (i.e. add a row) by typing new data
into the last row of the DataGridView, in my case, the data doesn't
appear to be pushed into the bound DataSet. When I do an DataAdapter
update (after building the insert, select, update, and delete commands)
on the data set, some of the fields are null, even though they were
filled in and the update of the database table fails, because a
particular field is null (again, even though I set that column's date
to a non-null value).
 
C

Cor Ligthert [MVP]

Right, but if you make a change (i.e. add a row) by typing new data
into the last row of the DataGridView, in my case, the data doesn't
appear to be pushed into the bound DataSet. When I do an DataAdapter
update (after building the insert, select, update, and delete commands)
on the data set, some of the fields are null, even though they were
filled in and the update of the database table fails, because a
particular field is null (again, even though I set that column's date
to a non-null value).
And did you do one of those methods that I showed you in my last reply
before that update?
(Normally with 2.0 the bindingsource.endedit)

Cor
 
R

roybrew

What is the correct DataGridView event to invoke the "EndEdit"
operation. It seems like many of the events (RowsAdded, UserAddedRow)
are too early in the edit process to invoke the EndEdit. They seem to
fire when I start typing in the first column of the new row. Invoking
"EndEdit" at that point will take the cell out of edit mode, which is
not the behavior I want.

roy
 
R

roybrew

Never mind Cor. I figured it out. But you helped me "get there".
When the RowLeave event gets fired, I check to make sure that my column
index is my last column and if so, things work appropriately. What I
have is a grid with 6 columns -- 4 of them hidden. Two of these are id
columns (one a primary key) that I don't need to display. When I
originally received the RowsAdded or UserAddedRow events, I believe it
was too early in the edit cell process. I was pre-populating my hidden
columns with "legal" values, but it was too soon. Now if I wait until
the RowLeave event is fired AND my last column was just filled with
data, this is the appropriate time to pre-populate these hidden columns
I mentioned above. So as it turns out, I don't even need to invoke
either of the "EndEdit" methods you mentioned. My database updates
work fine now. Thanks for steering me down the right path.

roy
 
Ad

Advertisements

C

Cor Ligthert [MVP]

Roy,

I wrote "before you do that update". That procedure is the place where you
have to do it.

And if you check in that for the haschanges than exactly before that.

Otherwise show some code than we can see why it is not working for you.

Cor
 
R

roybrew

Ok thanks. I'm on the right track now..
Roy,

I wrote "before you do that update". That procedure is the place where you
have to do it.

And if you check in that for the haschanges than exactly before that.

Otherwise show some code than we can see why it is not working for you.

Cor
 
Ad

Advertisements


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