Click here to Skip to main content
15,565,403 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:

C#
var db = new XXXXDataContext();
if(....)
 dg.ItemsSource = db.tableA;
else
 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?
Posted
Comments
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!
--SA
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:

C#
<datagridtextcolumn width="Auto" header="TableAID" binding="{Binding TableACode, Mode=TwoWay, Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" />
 
Share this answer
 
Comments
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