ListObject does not update DataSource when cell value changes

  • Thread starter Sébastien Gillet (EzGlobe.com)
  • Start date
S

Sébastien Gillet (EzGlobe.com)

This causes the DataSource (a DataSet) to not being in sync with the values
displayed by the ListObject.

The underlying DataSource is updated only when a new ListObject row is added
from the Worksheet. But if cell values of this last added row is updated by
user, the changes are not reflected into the underlying DataSet.

The documentation (http://msdn2.microsoft.com/en-us/library/bybtbt99.aspx)
reports "You do not need to save ListObject changes to the in-memory data
source. When you bind a ListObject control to data, the ListObject control
automatically saves changes to the in-memory data source without requiring
additional code." But it's not the case here.

Steps to Reproduce

* Under Visual Studio 2008, creates a new Excel 2007 Workbook project
(VB.Net).
* Create a new DataSet item to the project.
* Using the DataSet designer, add a DataTable to the DataSet. Name it
DataTable1 and add two String-typed DataColumn DataColumn1 and DataColumn2.
* Save DataSet and select Data > Show Data Sources menu.
* From the Data Sources panel, drag the DataTable1 onto Sheet1 of the Excel
Workbook. This automatically adds the DataTable1ListObject and
DataTable1BindingSource controls as well as an instance of DataSet1.
* Also add a Button onto onto Sheet1 of the Excel Workbook, and add handler
to the Click event.
* In the Button1.Click event handler add a breakpoint or code to inspect
content of the DataSet1.DataTable1.Rows and
DataSet1.DataTable1.GetChanges.Rows collections at run-time.
* Make the same for the DataTable1ListObject.Change event.
* Start Debugging the Project (F5). This shows up the Excel workbook with an
empty instance of the ListObject representing the 2 columns of the underlying
DataTable1.
* Add some values into cells of the first row of the ListOject (like "ABC",
"DEF"), and then select another cell away from the ListObject. This raises
the DataTable1ListObject.Change event. If you inspect content of the
underlying DataTable1, you can see this change has been reflected.
* Now change cell values of the ListObject row you just added with "123",
"456", and then select another cell away from the ListObject. The
DataTable1ListObject.Change event is NOT raised. Inspect content of the
underlying DataTable1, you can see this last changes have NOT been reflected
at all. DataTable1.GetChanges still returns values of the row when it has
been first added ("ABC", "DEF instead of "123", "456").

Actual Results

Changing value of cells bound to ListObject does not raise the
ListObject.Change event nor update the underlying DataSource accordingly.
This behavior can also be observed when:
* Loading existing data into the ListObject, changing some values / adding
some new rows, and then attempting to get changes from the underlying DataSet
using DataSet1.DataTable1.GetChanges().
* Using a BindingSource component or not.

Expected Results

As soon as user changes a cell value and validates by changing current
selection or typing ENTER, the ListObject.Change event should be raised and
underlying DataSource (DataSet) being updated accordingly.

Are we supposed to call any method to ensure the ListObject well
detects/propagates changes to the underlying DataTable?

Many thanks in advance for your help.

Best Regards,

Sébastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top