views:

31

answers:

2

Hello,

I have a grid (DevExpress XtraGrid, if that matters) which is bound to a LINQ to SQL Entity property.

gridItems.DataSource = purchaseOrder.PendingItemsGrouped;

Well, the grid is being displayed properly,and I can see the purchase items that are pending. The problem arises when purchaseOrder.PendingItemsGrouped gets changed ... once that happens, the grid does not reflect the changes.

The exact procedure is as following: The user selects a row from the grid, inserts a serial number on a specific textbox, and then hits enter effectively receiving this item from the purchase order, and inserting it into stock.

inventoryWorker.AddItemToStock( userSelectedItem, serialNumber );

The item gets properly inserted to the inventory, but the grid still shows the item as if it is still awaiting it to be received.

How do I solve this problem? Do I really need to re-bind the grid so the changes can be reflected?

I even tried instead of:

gridItems.DataSource = ...;

This:

gridItems.DataBindings.Add( new Binding( "DataSource", purchase, "PendingItemsGrouped" ) );

But couldn't solve the problem. Thank you very much for your time,

Isaac.

OBS: Re-Binding the Grid works, but my question is ... is that even the proper way of doing things? I feel like I'm miles off the right track.

+1  A: 

I have not tried it myself but Bindable LINQ allows to achieve it.

Giorgi
I appreciate your answer - does that mean that there's no way of doing it besides using Bindable LINQ?Thanks!
Isaac
+1  A: 

Calling databind is actually the right approach when you think about how databinding in webforms works. In all examples when databinding to objects, calls to databind happen whenever the collection is modified.

The reason it feels wrong is because its a lot cleaner to use a DataSourceControl, such as a LinqDataSourceControl or ObjectDataSourceControl, where all that stuff is handled for you.

Two things that might help you along this path is when using a LinqDataSourceControl, you might need to override the various -ing methods (Selecting, Inserting, Deleting) etc, in order to add additional filtering and logic.

The other thing that springs to mind is http://multitierlinqtosql.codeplex.com/. Especially the section on Custom ObjectDataSource.

SteadyEddi
Thanks for the complete answer.I appreciate it.
Isaac