private void InitializeLocationsGrid() { gridLocations = new ListView { Name = "gridLocations", WidthRequest = 250, HeightRequest = 400, AllowMultipleSelect = false }; gridLocations.Selection.Changed += Selection_Changed; gridLocations.ColumnController = new ColumnController { new Column(Translator.GetString("Location"), "Name", 1, "Name") }; scwLocations.Add(gridLocations); gridLocations.Show(); allLocations = Location.GetAll(); bool recreated = false; bool retry; do { retry = false; allStartNumbers = OperationNumberingInfo.Get(); if (allStartNumbers.Length == 0) { OperationNumberingInfo.Create(); recreated = true; allStartNumbers = OperationNumberingInfo.Get(); } allStartNumbersPerLocation.Clear(); foreach (Location location in allLocations) { Location l = location; List <OperationNumberingInfo> operations = allStartNumbers.Where(o => o.LocationId == l.Id).ToList(); if (operations.Count == 0 && !recreated) { OperationNumberingInfo.Create(); retry = true; recreated = true; break; } foreach (var info in operations) { info.UsageDescription = Translator.GetString("Calculating..."); } allStartNumbersPerLocation.Add(new KeyValuePair <long, BindingListModel <OperationNumberingInfo> > (location.Id, new BindingListModel <OperationNumberingInfo> (operations))); } } while (retry); DataHelper.FireAndForget(() => { numbersUsagePerLocation = OperationNumbersUsage.Get(); numbersUsageStarts = OperationNumbersUsage.GetUsagesStarts(); Timeout.Add(0, () => { try { UpdateDocumentsUsage(); } catch (ArgumentOutOfRangeException) { } return(false); }); }); allStartNumbersPerLocation = allStartNumbersPerLocation.OrderBy(p => p.Value.Min(o => o.StartNumber)).ToList(); // Use a model with natural order by the operation number intervals gridLocations.Model = new BindingListModel <Location> (allStartNumbersPerLocation.Select(d => allLocations.Find(p => p.Id == d.Key))); lblCurrentLocationsValue.SetText(allLocations.Count.ToString("N", formatBigNumber)); if (gridLocations.Model.Count <= 0) { return; } gridLocations.FocusRow(0); gridLocations.Selection.Select(0); gridLocations.ScrollToV(0); }