Click here to Skip to main content
15,613,470 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a DataGrid that displays one of several tables:

var db = new XXXXDataContext();
 dg.ItemsSource = db.tableA;
 dg.ItemsSource = db.tableB;

This works, but the DataGrid is not updated with changes in the database. How do I set
the binding mode to TwoWay in code behind?
Sergey Alexandrovich Kryukov 26-Oct-11 19:00pm    
And what, if you use just one way, DataGrid updates changes in database automatically? Tell me about it!
Bill S 26-Oct-11 19:43pm    
Make sure your binded to the DataView.
Orcun Iyigun 26-Oct-11 19:45pm    
Make sure you Bind again after making changes (CRUD operations. (Create, Delete, Update)).
BillWoodruff 26-Oct-11 20:22pm    
I think you should have posted this as an answer, since I'd guess it's probably is the reason the OP is not observing two-way binding. Then I could vote for your answer :)
Julio Kuplinsky 27-Oct-11 7:54am    
rebinding didnt help

1 solution

All of your data grid columns should be TwoWay mode enabled as:

<datagridtextcolumn width="Auto" header="TableAID" binding="{Binding TableACode, Mode=TwoWay, Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" />
Share this answer
Julio Kuplinsky 27-Oct-11 4:56am    
whats your idea of code behind?

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