Solved

Data Grid View Control Record Update Issue

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

863 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

27 Experts available now in Live!

Get 1:1 Help Now