473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

changes in DataGrid and DataTable.GetChanges()

Hello,

I have a DataGrid(View) and a DataTable. The DataTable is displayed in the
DataGridView:

dataGridView.DataSource = theTable;

The user is allowed to select some rows and then the following
snippet updates some values in the selected rows:

foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
row.Cells["theColumnName1"].Value = someCalculatedValue1;
row.Cells["theColumnName2"].Value = someCalculatedValue2;
}

Then the following line of code is executed:

MessageBox.Show(theTable.GetChanges().Rows.Count.T oString());

It turns out that the number of rows returned by GetChanges() is always one
lower than the number of selected rows in the DataGridView. When n rows are
selected, the foreach loop is executed for n rows, n rows change in the
DataGridView, but only n-1 rows are returned by theTable.GetChanges()...

Updating complete rows at once in the DataGridView using row.SetValues(...)
doesn't make a difference. The last selected row, though changed in the
DataGridView, is never actually changed in the DataTable.

Could anyone help me out please?

Thanks a lot!

Jochen

Jul 21 '05 #1
2 8465
Hi,
I haven't worked a lot with datagrids but this is my best guess.

The datagrid doesn't seem to detect changes to a row until you actually move
out of the cell that you just changed. That may be the reason that the
getChanges() method never includes the last row changed.

Try adding this code to your project, before you call the getChanges method,
replacing the "myDataSet.Tables[0]" with your datatable:

CurrencyManager cm = (CurrencyManager)BindingContext[myDataSet.Tables[0]];
cm.Position = -1;

-rotarinn

"JochenZ" wrote:
Hello,

I have a DataGrid(View) and a DataTable. The DataTable is displayed in the
DataGridView:

dataGridView.DataSource = theTable;

The user is allowed to select some rows and then the following
snippet updates some values in the selected rows:

foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
row.Cells["theColumnName1"].Value = someCalculatedValue1;
row.Cells["theColumnName2"].Value = someCalculatedValue2;
}

Then the following line of code is executed:

MessageBox.Show(theTable.GetChanges().Rows.Count.T oString());

It turns out that the number of rows returned by GetChanges() is always one
lower than the number of selected rows in the DataGridView. When n rows are
selected, the foreach loop is executed for n rows, n rows change in the
DataGridView, but only n-1 rows are returned by theTable.GetChanges()...

Updating complete rows at once in the DataGridView using row.SetValues(...)
doesn't make a difference. The last selected row, though changed in the
DataGridView, is never actually changed in the DataTable.

Could anyone help me out please?

Thanks a lot!

Jochen

Jul 21 '05 #2
I had the same guess, and so I tried to run the foreach loop twice in
succession. This way, it would surely have left the last selected row in the
same way as it had left the others. But that didn't help...

Jochen

"rotarinn" wrote:
Hi,
I haven't worked a lot with datagrids but this is my best guess.

The datagrid doesn't seem to detect changes to a row until you actually move
out of the cell that you just changed. That may be the reason that the
getChanges() method never includes the last row changed.

Try adding this code to your project, before you call the getChanges method,
replacing the "myDataSet.Tables[0]" with your datatable:

CurrencyManager cm = (CurrencyManager)BindingContext[myDataSet.Tables[0]];
cm.Position = -1;

-rotarinn

"JochenZ" wrote:
Hello,

I have a DataGrid(View) and a DataTable. The DataTable is displayed in the
DataGridView:

dataGridView.DataSource = theTable;

The user is allowed to select some rows and then the following
snippet updates some values in the selected rows:

foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
row.Cells["theColumnName1"].Value = someCalculatedValue1;
row.Cells["theColumnName2"].Value = someCalculatedValue2;
}

Then the following line of code is executed:

MessageBox.Show(theTable.GetChanges().Rows.Count.T oString());

It turns out that the number of rows returned by GetChanges() is always one
lower than the number of selected rows in the DataGridView. When n rows are
selected, the foreach loop is executed for n rows, n rows change in the
DataGridView, but only n-1 rows are returned by theTable.GetChanges()...

Updating complete rows at once in the DataGridView using row.SetValues(...)
doesn't make a difference. The last selected row, though changed in the
DataGridView, is never actually changed in the DataTable.

Could anyone help me out please?

Thanks a lot!

Jochen

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JochenZ | last post by:
Hello, I have a DataGrid(View) and a DataTable. The DataTable is displayed in the DataGridView. The user is allowed to select some rows and then the following snippet updates some values in the...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
2
by: Geir Sanne | last post by:
hi!! how am i supposed to update the db witht he changes the user make in webpage am trying to make a simple page that have a grid bound to a table the user can delete,add or update the grid...
4
by: Peter Proost | last post by:
Hello group, what would be the best way to do the next thing: I've got a grid form with about 15000 records, when I double click a row a detail form is opened and the user can modify and save...
12
by: Art | last post by:
Hi, I need help -- again -- I have a DataGrid with a DataTable as its source. It displays wonderfully when I put in some test data (withinin the code). Now, I'd like to change one of the...
2
by: JochenZ | last post by:
Hello, I have a DataGrid(View) and a DataTable. The DataTable is displayed in the DataGridView: dataGridView.DataSource = theTable; The user is allowed to select some rows and then the...
2
by: Brian Hoops | last post by:
I have a windows forms datagrid and I would like to be able to recognize when changes have been made in order to perform the update. I tried the following, which works well, but only if the user...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
2
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
How can I reconcile changes between two data table and create a subset of those changes. I have two data tables with same schema which gets populated from two different xml files. I want to get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.