Solved

Data Grid View Control Record Update Issue

Posted on 2006-11-01
2
210 Views
Last Modified: 2010-04-23
I have a Data Grid View Control that displays data.  I reference all the rows programatically for that grid and then populate data in their appropriate fields.  It uses the bound data adapter and creates a command and then uses the update command to update the appropriate record.

The problem that I have is when I first load up the grid, the cursor is set to the first record in the grid.  I was initially having a problems during the update on that first record.  The update command executes successfully and then does so on the latter records.  However, when i check the table, the data isn't updated for that 1 particular row.  

I created a workaround to where I set focus to a cell in a different row than the row that is currently being updated so I always have my cursor on a row that ISN'T being updated.

However, if my dataset only has 1 row, I cannot set it to a different row, because it is the only row.  I cannot add new rows because it is bound.  How can I make the change and have the changes take effect for the row that i currently have active.  

0
Comment
Question by:jpmc_cmsops
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 17854407
There is a binding manager that handles communications between the datagridview and the datatable.  It only passes edits made in the datagridview to the datatable when it knows that the editing on a single row is finished.  If you move to a different row, it knows that "automatically": that's how your workaround works.  But you can force it to do it even when focus stays on the same row by calling the binding manager's .EndCurrentEdit (or .EndEdit).

That's the general theory.  But I've been a bit equivocal about the precise details - e.g. ".EndCurrentEdit (or .EndEdit)" - because the exact syntax depends on your precise set up and I don't know that.  Possibilities include

   BindingContext(<datatable>).EndCurrentEdit

where <datatable> is the DataSource of your DataGridView, or

   myBindingSource.EndEdit

where there is a specific named BindingSource that is your DataGridView's DataSource, or

   myDataGridView.DataSource.EndCurrentEdit

which will work if the DataSource is a DataTable, or

   myDataGridView.DataSource.EndEdit

which will work if the DataSource is a BindingSource.

Have a play with variations on that theme.  Stick one of them just before your update command.  If that errors, try another.  If you can't sort it out by doing that, come back with details of how your DataViewGrid is bound to the data table.

Roger
0
 

Author Comment

by:jpmc_cmsops
ID: 17858572
Roger-

THANK YOU VERY MUCH!!!.

I used the following code:

gridData.BindingContext(gridData.DataSource).EndCurrentEdit()

It works perfect.

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question