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
35
XamDataGrid Arrow Key Navigation not correctly working
posted

Hello I am pretty new to using Infragistics and have been tasked to take over code that has been written by a previous developer.
Based on my observations, this developer implemented a custom Infragistics XamDataGrid that allows one to bind to the SelectedItems property as the SelectedItems property does not allow binding by default according to him,.

Preview of code:

<CustomControls:BSIXamDataGrid x:Uid="xamDataGridCam" x:Name="xamDataGridCam"
                                  DataSource="{Binding QueryItems}"   
                                  BindableSelectedItems="{Binding SelectedItems, Mode=TwoWay}"   
                                  GroupByAreaLocation="None"
                                  GotKeyboardFocus="xamDataGridCam_GotKeyboardFocus"
                                  AutoFit="True"
                                  Grid.Row="4"
                                  VerticalContentAlignment="Stretch"
                                  ScrollingMode="Immediate"
                                  ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                  ScrollViewer.CanContentScroll="True"
                                  VerticalAlignment="Stretch"
                                  RecordsInViewChanged="xamDataGridCam_RecordsInViewChanged"
                                  RecordFilterDropDownPopulating="xamDataGridCam_RecordFilterDropDownPopulating"   
                                  AssigningFieldLayoutToItem="xamDataGridCam_AssigningFieldLayoutToItem">

There seems to be a bug where if I try to navigate through the rows in a table using the arrow keys, it will only go to the next row then go back to the previous like so:

Could anyone please help me understand what's possibly going on? Thanks in advance!

Parents Reply
  • 26425
    Offline posted in reply to Shawn Quach

    Hello Shawn, 

    I strongly encourage you to review the following blog that contains a sample ( at the bottom of the page) demonstrating a working scenario of a derived XamDataGrid with a custom "selecteditems" dependency property. The blog was written before 14.2 when SelectedDataItems wasn't available. If the issue still occurs with the following implementation let me know. 

    eg. 

    public class MyXamDataGrid : XamDataGrid
        {
            public static readonly DependencyProperty NewXDGSelectedItemsProperty = DependencyProperty.Register("NewXDGSelectedItems", typeof(IEnumerable), typeof(MyXamDataGrid));
    
           
            public IEnumerable NewXDGSelectedItems
            {
                get { return (IEnumerable)GetValue(NewXDGSelectedItemsProperty); }
                set { SetValue(NewXDGSelectedItemsProperty, value); } 
            }
    
            private  void NewXDGSelectedItemsPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
            {
                this.SelectedItemsChanged -= new EventHandler<SelectedItemsChangedEventArgs>(MyXamDataGrid_SelectedItemsChanged);
                this.ActiveRecord = null;
                if (!this.IsMouseOver)
                {
                    this.SelectedItems.Records.Clear();
                }
    
                if (args.NewValue != null)
                {
    
    
                    foreach (var item in args.NewValue as IEnumerable)
                    {
    
                        this.SelectedItems.Records.Add(this.GetRecordFromDataItem(item, false));
                        //(item as TestItem).IsSelected = true;
                    }
                }
                this.SelectedItemsChanged += new EventHandler<SelectedItemsChangedEventArgs>(MyXamDataGrid_SelectedItemsChanged);
            }
    
            public MyXamDataGrid() :base()
            {
                this.SelectedItemsChanged += new EventHandler<SelectedItemsChangedEventArgs>(MyXamDataGrid_SelectedItemsChanged);
                NewXDGSelectedItemsProperty.OverrideMetadata(typeof(MyXamDataGrid), new FrameworkPropertyMetadata(NewXDGSelectedItemsPropertyChanged));
    
            }
    
    
            void MyXamDataGrid_SelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e)
            {
                List<object> selectedItems = new List<object>();
    
                foreach (object selectedItem in base.SelectedItems)
                {
                    if (selectedItem is Cell)
                        selectedItems.Add(((selectedItem as Cell).Record as DataRecord).DataItem);
    
                    else if (selectedItem is DataRecord)
                        selectedItems.Add((selectedItem as DataRecord).DataItem);
                }
    
                NewXDGSelectedItems = selectedItems as IEnumerable;
            }
     
          
        }

Children