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!
Hi Michael,I have reviewed the blog along with the code and I can verify that the MyXamDataGrid is identical to mines "BSIXamDataGrid". I was not able to run the application as I do not have an extra license for Infragistics to use. However I do feel the problem may be in the xaml file that I have posted "QueryUserControl.xaml".
<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"> <CustomControls:BSIXamDataGrid.Resources> <Style x:Uid="Style_2" TargetType="{x:Type igDP:DataRecordCellArea}" BasedOn="{StaticResource DataRecordCellAreaStyle}"/> </CustomControls:BSIXamDataGrid.Resources> <CustomControls:BSIXamDataGrid.ViewSettings> <igDP:GridViewSettings x:Uid="igDP:GridViewSettings_1" Orientation="Vertical" HeightInInfiniteContainers="100000"/> </CustomControls:BSIXamDataGrid.ViewSettings> <!-- Turn off cell editing. --> <CustomControls:BSIXamDataGrid.FieldSettings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_1" CellMinWidth="50" AllowGroupBy="True" AllowEdit="False" CellClickAction="SelectRecord" AllowRecordFiltering="True" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="None"/> </CustomControls:BSIXamDataGrid.FieldSettings> <CustomControls:BSIXamDataGrid.FieldLayouts> <igDP:FieldLayout x:Uid="igDP:FieldLayout_1"> <igDP:Field x:Uid="ItemImage" Name="ItemImage" Label=" "> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_2" AllowResize="False" Width="Auto" AllowRecordFiltering="False" AllowGroupBy="False"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Name" Name="Name" Label="{DynamicResource QueryControlGridColumnName}" IsScrollTipField="True"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_3" AllowRecordFiltering="True" AllowGroupBy="False" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="None" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Code" Name="Code" Label="{DynamicResource QueryControlGridColumnCode}"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_4" AllowEdit="False" CellWidth="20" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="{x:Null}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Building" Name="Building" Label="{DynamicResource QueryControlGridColumnBuilding}"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_5" AllowRecordFiltering="True" AllowGroupBy="False" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="None" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Room" Name="Room" Label="{DynamicResource QueryControlGridColumnRoom}"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_6" AllowRecordFiltering="True" AllowGroupBy="False" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="None" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Type" Name="Type" Label="{DynamicResource QueryControlGridColumnType}"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_7" AllowRecordFiltering="True" FilterOperandUIType="DropDownList" FilterOperatorDropDownItems="None" FilterOperatorDefaultValue="Contains" AllowGroupBy="False" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field x:Uid="Manufacturer" Name="Manufacturer" Label="{DynamicResource QueryControlGridColumnManufacturer}"> <igDP:Field.Settings> <igDP:FieldSettings x:Uid="igDP:FieldSettings_8" AllowRecordFiltering="True" FilterOperandUIType="DropDownList" FilterOperatorDefaultValue="Contains" FilterOperatorDropDownItems="None" AllowGroupBy="False" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </CustomControls:BSIXamDataGrid.FieldLayouts> <CustomControls:BSIXamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings x:Uid="igDP:FieldLayoutSettings_1" AllowRecordFixing="Top" HeaderPlacement="OnTopOnly" AllowDelete="False" RecordSelectorLocation="None" SelectionTypeRecord="ExtendedAutoDrag" AllowFieldMoving="WithinLogicalRow" HighlightAlternateRecords="False" AutoGenerateFields="False"/> </CustomControls:BSIXamDataGrid.FieldLayoutSettings> </CustomControls:BSIXamDataGrid>
I reproduced the behavior, it's definitely not anything in XAML that's causing it. The issue stems from updating NewXDGSelectedItems when grid's SelectedItemsChanged event is fired. I haven't been able to work around this. But you might be better off using a Behavior with your custom implementation. This was discussed here
Let me know if you have any questions.
Hi Michael,
I'm in the process of adding said Behavior in conjunction with my custom implementation but I'm having a bit of trouble. I believe this method fires as soon as the application launches when it really should run once the window containing the XamDataGrid is launched/opened:
protected override void OnAttached() { base.OnAttached(); Grid.SelectedItemsChanged += new System.EventHandler<Infragistics.Windows.DataPresenter.Events.SelectedItemsChangedEventArgs>(Grid_SelectedItemsChanged); SelectedItems.CollectionChanged += new NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged); }
The error is that the SelectedItems object appears to be null as it hasn't even been created in the first place:
Hello Shawn,
If you are implementing the Behavior approach, then I don't recommend also using a custom implementation of XamDataGrid. Do you have any requirements other than handling SelectedItems?
I attached a more refined sample demonstrating the Behavior working with a regular XamDataGrid. It's more efficient to use a Behavior than a custom implementation of XamDataGrid since you are not using SelectedDataItems in our newer versions.
Please review the sample attached below.
Grid_Binding_SelectedItems.zip
I'd like to add that the detach code wasn't working because I was passing the behavior instead of the grid.