Hello,
I'm trying to incorporate a xamDataGrid into an MVVM application.
I have the grid bound to an observable collection in my viewModel. This collection is of another viewModel object type.
Inside my grid, some of the editors are set to xamComboEditors which items are bound to another collections in my viewmodel.
I'm having trouble when using the AllowAddNew feature. If the user initializes the new row from a field with a combo editor in it, the new item is added to my collection, however the property setter from the combo select is lost. If the user initializes the new row from a text or even a check box editor, the new row is added to my collection and then the property setter is called. I was trying to change the DataItemUpdateTrigger value, but have not had any luck. I think I am missing something.
Here is the a simplified example of the code I am using:
Grid:
<igWPF:XamDataGrid Visibility="{Binding TimeEntryCalls, Converter={StaticResource NullVisibilityConverter}}"IsSynchronizedWithCurrentItem="True" DataSource="{Binding Path=TimeEntryCalls, Mode=TwoWay}" MaxHeight="200" > <igWPF:XamDataGrid.FieldLayoutSettings> <igWPF:FieldLayoutSettings AutoGenerateFields="False" AddNewRecordLocation="OnBottom" AllowAddNew="True" AllowDelete="True" /> </igWPF:XamDataGrid.FieldLayoutSettings> <igWPF:FieldLayout.Fields> <igWPF:UnboundField Name="Equip" Label="Vehicle" BindingPath="SelectedTimeCall.Equip" BindingMode="TwoWay" > <igWPF:Field.Settings> <igWPF:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" DataItemUpdateTrigger="OnCellValueChange" > <igWPF:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.EquipmentForDivision, IsAsync=True}" /> <Setter Property="SelectedItem" Value="{Binding DataItem.SelectedTimeCall.Equip, Mode=TwoWay}"/> <Setter Property="DisplayMemberPath" Value="EquipCode" /> <Setter Property="AcceptsArrowKeysInEditMode" Value="True"/> </Style> </igWPF:FieldSettings.EditorStyle> </igWPF:FieldSettings> </igWPF:Field.Settings> </igWPF:UnboundField> <igWPF:UnboundField Name="IsDriver" Label="Driver" BindingPath="SelectedTimeCall.IsDriver" BindingMode="TwoWay" Converter="{StaticResource IgnoreNewItemPlaceHolderConverter}" > <igWPF:Field.Settings> <igWPF:FieldSettings EditorType="{x:Type igEditors:XamCheckEditor}" DataItemUpdateTrigger="OnCellValueChange"> </igWPF:FieldSettings> </igWPF:Field.Settings> </igWPF:UnboundField> <igWPF:UnboundField Name="CallHours" Label="Hours" BindingPath="SelectedTimeCall.CallHours" BindingMode="TwoWay"> <igWPF:Field.Settings> <igWPF:FieldSettings DataItemUpdateTrigger="OnLeaveCell" EditAsType="Core:Double"/> </igWPF:Field.Settings> </igWPF:UnboundField> </igWPF:FieldLayout.Fields> </igWPF:FieldLayout> </igWPF:XamDataGrid.FieldLayouts></igWPF:XamDataGrid>
Code from my viewModel:
private ObservableCollection<CallViewModel> timeEntryCalls;
public ObservableCollection<CallViewModel> TimeEntryCalls{ get { return timeEntryCalls; } set { timeEntryCalls = value; OnPropertyChanged(); }}
public List<EQUIPMENT> EquipmentForDivision { get; set; }
void timeEntryCalls_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e){ if (e.Action == NotifyCollectionChangedAction.Add) { try { foreach (CallViewModel call in e.NewItems) { //calling methods inside CallViewModel to initialize values } } catch (Exception ex) { //handle any exceptions } } OnPropertyChanged("TimeEntryCalls");}
Hello Laura,
Thank you for your post. I have been looking into it and I created a sample project for you following your scenario and everything seems to work ok on my side. I only set the DataType of the UnboundField to the object type that it will use. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
Hi,
I have modified the sample to reproduce what I am experiencing. I have added another class for City as well as the collection change event for the person collection. In the collection change event I am initializing the Address object and setting one of its properties. Now when you select the new row and change the City, the new item event is being fired on the collection, but the City setter is not being called. Also, in this example the City is not being displayed unless its in edit mode, I'm wondering if a converter will fix that up however.
Thanks
I have been looking into the modified sample and I noticed that there is a Binding error in the Output, which is the reason why the Values are not shown. When I changed the BindingPath of the UnboundField to the correct value everything works as expected. It should be "Location.City", not "City" because the DataContext there is Person. Please let me know if you need further clarifications on this matter.
That did the trick. I set the DataType in my application and fixed up the BindingPath. Now the collection change event is fired followed by the setter.
Thanks!!
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.