Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Datagrid and Databinding
7 replies. Latest Post by yifung on November 4, 2009.
(0)
R.Vijay
Member
0 points
3 Posts
11-03-2009 9:41 AM |
Hi,
i've a class named Employee which has two properties Name and Age.I've created a list of employees and set as the ItemsSource and added the below columns to the datagrid.<data:DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
But when i try to edit the cell ,the source gets the latest values which is the oppsoite behaviour of oneway mode.Guess,OneWay(from source to target ) is the default mode in databinding .Does silverlight has OneWayToSource Binding Mode ?
Ardman
Contributor
3434 points
946 Posts
11-03-2009 10:06 AM |
The Mode on the Binding is set to OneWay indicating that the Name will come from the Binding Source (your Employee object) to be bound to the DataGridTextColumn, but changes made in the UI will not be sent back to the Binding Source.
11-03-2009 10:29 AM |
yeah,i too assumed it in the same way as you mentioned .But the datagrid behaves in a peculiar way .I think ,by default it uses the two way mode .
I tried the same scenario with textbox and it works perfect.Not sure where it goes wrong ,when i try it with the datagrid.
MComeauS2S
284 points
155 Posts
11-03-2009 11:17 AM |
You need to add Mode=TwoWay on your binding because DataGrid column bindings are OneWay by default.
yifung
3315 points
541 Posts
11-03-2009 6:00 PM |
Yes, the DataGrid by default changes Bindings to be TwoWay. If you don't want to edit you can set IsReadOnly to true for particular columns or the entire DataGrid
11-03-2009 11:16 PM |
Thanks yifung.
Is this the expected behaviour in Datagrid or is it a bug ?
11-04-2009 5:42 AM |
Looks like its expected behaviour:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid(VS.95).aspx
11-04-2009 1:21 PM |
Yes, the behavior is by design.