Solved

Data Grid View Control Record Update Issue

Posted on 2006-11-01
2
208 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now