Solved

Data Grid View Control Record Update Issue

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

20 Experts available now in Live!

Get 1:1 Help Now