Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Programmatically adding rows to a DataGrid bound to LINQ table

$
0
0

I have a DataGrid bound to a LINQ-TO-SQL table object: dataGrid.ItemsSource = myDataContext.MyItems;

This lets the user edit and insert database items without me having to implement a single line of code.

Great! BUT: I can't figure out how to insert new items programmatically. The DataGrid doesn't update when i add items to the table (myDataContext.MyItems.InsertOnSubmit(newItem)).

Of course i could copy the whole table to an observable collection, but keeping this in sync with the database sounds like a tedious job. Any better suggestions?

It would be ok for me to just fill text data into the last ("empty") row of the grid and let the user trigger the insert event (when the row loses focus).



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>