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
530
XamDataGrid (v10.1) causes bound CollectionViewSource's View.CurrentChanging to fire three times when row changed via mouse click and cancelled in View.CurrentChanging Event
posted

XamDataGrid (v10.1) causes a bound CollectionViewSource's (of type BindingListCollectionView) View.CurrentChanging to fire three times when cancelled inside the CollectionViewSource View.CurrentChanging event.  Inside the CollectionViewSource.CurrentChanging, e.Cancel is being set to true, which sends the CurrentItem back to what was the originally selected item.  When this is done purely in code, the CurrentChanging event fires once.  When the CollectionViewSource is bound to a XamDataGrid and the user changes rows in the grid (and the event is cancelled in the View.CurrentChanging event), the ViewCurrentChanging fires three times. 

Also, when using the keyboard to change rows, the View.CurrentChanging fires once.  And when the event is not cancelled, the View.CurrentChanging fires once.  And if you click in the record selector area to change rows, the View.CurrentChanging fires once.

Only when using the mouse click to change rows, and it is clicked in another row's cell area, and the View.CurrentChanging is cancelled, does the XamDataGrid cause the View.CurrentChanging to fire three times and six sets of DataGrid_RecordDeactivating/DataGrid_RecordActivating pairs fire in this scenario.

Any hints as to why this would happen?  Is it related to this :  http://wpf.codeplex.com/WorkItem/View.aspx?WorkItemId=8417 ?

The DataGrid is about as simple as it can be.  In this simple example (below) the View.CurrentChanging fires twice instead of three times as it does in my application.  But in any case, we do expensive (timewise) database validations in this routine and don't want it to fire multiple times when the event (from the user perspective) really happened once.

<Window x:Class="ViewChangingBug.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:iwdp="http://infragistics.com/DataPresenter"  
    Title="Window1" Height="300" Width="300">
    <Grid>
  <iwdp:XamDataGrid x:Name="DataGrid" IsSynchronizedWithCurrentItem="True" >
   <iwdp:XamDataGrid.FieldLayoutSettings>
    <iwdp:FieldLayoutSettings AutoGenerateFields="false" />
   </iwdp:XamDataGrid.FieldLayoutSettings>
  </iwdp:XamDataGrid>       
    </Grid>
</Window>

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Infragistics.Windows.DataPresenter;

namespace ViewChangingBug
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    public Window1()
    {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(Window1_Loaded);
    }

    void Window1_Loaded(object sender, RoutedEventArgs e)
    {
      Collection<Test> tests = CreateCollection();

      CollectionViewSource cvs = new CollectionViewSource();
      cvs.Source = tests;
      cvs.View.CurrentChanging += new System.ComponentModel.CurrentChangingEventHandler(View_CurrentChanging);

      Field field = new Field("Name", "Test");
      field.Column = 0;
      FieldLayout gridLayout = new FieldLayout();
      gridLayout.Fields.Add(field);
      DataGrid.FieldLayouts.Add(gridLayout);
      DataGrid.DataSource = cvs.View;
    }

    private Collection<Test> CreateCollection()
    {
      Collection<Test> tests = new Collection<Test>();
      Test test = new Test();
      test.Name = "Test1";
      tests.Add(test);
      test = new Test();
      test.Name = "Test2";
      tests.Add(test);
      test = new Test();
      test.Name = "Test3";
      tests.Add(test);

      return tests;
    }
    void View_CurrentChanging(object sender, System.ComponentModel.CurrentChangingEventArgs e)
    {
      System.Diagnostics.Debug.Write("In View.CurrentChanging\n");
      e.Cancel = true;
    }
  }

  public class Test
  {
    string _name;
    public String Name
    {
      get { return _name; }
      set { _name = value; }
    }
  }
}

 

  • 138253
    Offline posted

    Hi,

     

    We have shipped out a new service release where your issue is resolved. I'd be glad to find out if you had tested it out and if it had met your requirements.

    You can download the Service Releases by logging to our web site and going to My IG \My Keys and Downloads.

     

    Thank you for using Infragistics Components.

  • 138253
    Offline posted

    Hello,

     

    I have logged this with development under ID: 84057 and I have also created a support ticket on your behalf: CAS-70084-DJKBV3  and have linked the development issue to it, so that you can get automatically updated, when a Service Release containing the fix is available for download. You can get the new version from our website’s “My IG”, “My Keys & Downloads” tags: https://ko.infragistics.com/Membership/Default.aspx?panel=Downloads#Downloads

     

    You can also monitor the support ticket’s progress through the “My Support Activity” tag: https://ko.infragistics.com/Membership/MySupport.aspx