Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
XamComboEditor in xamDataGrid not calling setter in underlying property when adding new row
posted

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");
}

Parents
  • 138253
    Verified Answer
    Offline posted

    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.

    XamDataGridComboEditor.zip
Reply Children