Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

There is probably something small I'm missing, but I can't figure it out.

I have a Class which has an EntitySet<t> as one of its members. I also have a WPF Page with a DataGrid. I have create a ViewModel of my class, with a Public Property for the EntitySet within my class (with the OnPropertyChanged events and blah blah).

I have the DataGrid's ItemsSource bound to the EntitySet property of the ViewModel.

It get all the data in the Entity set displayed on the DataGrid for a class that already has data in the EntitySet, but when I create a new instance of my class and initialise the EnitySet, the DataGrid shows nothing.

I would like to be able to add\remove data to the EntitySet via the DataGrid (so that if I use LINQ2SQL's DataContext.SubmitChanges(), my database is updated). How would I go about doing this, and how would I be able to set the columns to comboboxes where the field needs to be such?

thanks in advance

Ok, after playing around with it a bit, I noticed that if the entity set does not contain any entries (as is the case above) the columns and their names are not created, but there does exist a blank record.

So my question should be, how can I add the columns to the datagrid?
Posted
Updated 7-Nov-11 20:06pm
v3

As I realized, you bound the ItemsSource property of your control to an empty collection and, filled your collection afterwards. Possible reason of the disappearance of the items is that the binding isn't notified about the collection's changes.


In order to let the binding to be notified about the collection's changes, you have to bind the ItemsSource property to a collection that implements INotifyCollectionChanged. For that purpose you can use ObservableCollection.


You can replace the EntitySet property in your view-model with a corresponding ObservableCollection property.

 
Share this answer
 
Comments
PJ du Preez 7-Nov-11 15:57pm    
" As I realized, you bound theItemsSource property of your control to an empty collection and, filled your collection afterwards."

Nope, i'm starting off with an empty entityset bound to the datagrid and want to full data in via the grid. I've tried using observable collection, but gave up halfway. I thought that I could use the same principles with a binding a datagrid to an entityset property as when binding a textbox to a string property.

Is observablecollection like a wrapper?
Ok, so I got this working... I just needed to manually create the columns that I want on the datagrid and bind that to the appropriate properties of the class contained in the Entity set. really simple actully
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900