Marcin Bator
Marcin Bator

Reputation: 381

C# Apply changes made to copied DataTable

Hello everyone!

I stumbled upon a problem while trying to display and edit data in multiple GridControls (DataGridViews) using multiple DataTables.

I have a main DataTable that stores data about Users (just an example) and a set of another DataTables that store different data (also about users).

The way I am displaying them now is as follows: All additional DataTables have a „UserId” column and when the row is clicked in main GridControl (Users), the data for other GridControls is copied using

DataTable.Select(„UserId = …”) 

method and then the data for only selected user is being displayed in GridControl. The DataTable with full data is being stored in a different variable and each time the MainGrid row is clicked, the full data is used to generate DataTable for selected user.

The displaying data works okay, but when it comes to editing those additional GridControls, there are some problems. For editing them I am using SqlDataAdapters that generate full DataTable for each of additional tables and when the save button is clicked, they simply update the database.

The problem is that after I use

DataTable.Select(“UserId = …”)

if I edit the new table, the full table is not going to be affected by that.

On the other hand, I can’t just do

DataTable _NewTable = _OldTable 

because then if I try to remove rows with other User's data that I don't want to display, they’re going to be completely removed from the full DataTable.

As I am using a DevExpress controls, I could just set the DataSource of GridControl to the full table and apply a filter on the GridControl, but it would make filtering data more difficult for end user.

Do you have an idea on how to solve that problem so I can edit those "small" DataTables and then somehow update those changed rows in the full DataTable and be able to use SqlDataAdapter?

Thanks for help and sorry if I confused you!

Upvotes: 0

Views: 1282

Answers (2)

Marcin Bator
Marcin Bator

Reputation: 381

My problem has been resolved by @Vlad using DataView as data source for additional grid controls with row filter.

Upvotes: 0

VladOhotnikov
VladOhotnikov

Reputation: 1188

I think u must not copy values the child tables and pass it via reference into parent grid. Read about difference here. So then you will change child grid, it will also change parent grid.

P.S. Please post all your code for more detailed answer

Upvotes: 0

Related Questions