Posted 8 August 2017, 11:06 am ESTPlatform: Xamarin.Forms
OS: Android 4.4.4
I'm having problems with the selection in FlexGrid. It doesn't appear to be clearing the previously made selection when ItemsSource is changed.
The grid is defined in XAML:
<xuni_flexgrid:FlexGrid Grid.Row="4" Grid.Column="0" x:Name="grid" Margin="5, 0, 5, 0" CellPadding="1" DefaultRowHeight="21" AutoGenerateColumns="False" AllowSorting="False" IsReadOnly="True" HeadersVisibility="Column" />
The grid columns are built and added programmatically.
The grid is set up to accept the list of line items and by default select the first row:
grid.ItemsSource = ViewModel.Order.LineItems; // LineItems is of a type List<LineItem>
grid.Select(new GridCellRange(0, 0, 0, grid.Columns.Count - 1), false);
The user is free to select a different row (let's say they click on a second one), and then update the grid with a different LineItems collection. When this happens, the app goes through these two lines of code again, updating ItemsSource and selecting the first row. On the screen it looks fine: the grid displays a new set of rows, and the first one is selected.
However, when the user attempts to select the second row, the one they selected right before updating the grid, the grid does not react. The highlight does not move, and SelectionChanged event is not fired. It's like the grid displays the first row as selected, but internally it thinks the second row is selected. Clicking on the third row moves the selection, and now the user can finally click and select the second row.
How do I make sure the previous selection is removed when I update grid's ItemsSource?
So far I tried
- explicitly resetting the selection by calling
grid.Select(new GridCellRange(-1, -1), false);
grid.Selection = new GridCellRange(-1, -1);
- explicitly clearing the row collection by calling
grid.ItemsSource = new List<LineItem>();
grid.ItemsSource = null;
Nothing seems to be working.