Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Data Grid View Control Record Update Issue

Posted on 2006-11-01
2
Medium Priority
?
214 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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 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