Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a user control with a WPF Data Grid. I used this user control in a Windows form using Element Host. I can bind the data to the user control using ListCollectionView but when i make updates to the datagrid the changes are not reflected back.

I set the Mode = TwoWay but no use.
Any ideas? Here is a sample of my code:

UserControl.xaml
<my:DataGrid
ItemsSource="{Binding}"
HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" CanUserSortColumns="False"
AutoGenerateColumns="False"
RowHeaderWidth="20" RowHeight="25" Width="Auto" Height="Auto"
RowStyle="{StaticResource RowSelected1}"
CellStyle="{StaticResource RowSelected}"
GridLinesVisibility="Horizontal" >
<my:DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle1}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<my:DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</my:DataGrid.GroupStyle>
<my:DataGrid.Columns>
<Controls:LabelTextBoxColumn
Header="Tread BarCode" Width="2*"
HorizontalAlignment="Left" VerticalAlignment="Center"
ElementStyle="{StaticResource BaseLabelCellStyle}"
EditingElementStyle="{StaticResource BaseTextBoxCellStyle}"
Binding="{Binding Name,Mode=TwoWay}"/>
//The code in my Windows form frm1 is :
this.sdaTrueName.Fill(this.dstrueSrch1.dtTrue);
view = new ListCollectionView(this.dstrueSrch1.dtTrue.ToList());
view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
UserControlABC.DataContext = view;

I have to save the data back into my database.I am using Dataset and DataTables.

Please help me with any ideas ?
Posted
Updated 1-Jul-10 19:25pm
v2

1 solution

Hi,
Since you are using the List<> , the add,remove notifications are not triggered,therefore the target is not updated eventhough you updated the datasource.There is a class ObservableCollection<> that triggers the add , remove notifications itself and update the view accordingly.Otherwise you update the source and target explicitly , for eg:

C#
BindingExpression expression = BindingOperations.GetBindingExpression(thedatagrid, DataGrid.ItemsSourceProperty);
     if (null != expression)
     {
       expression.UpdateSource();
     }
 
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