private void initializeCollectionsDropdown() { var items = new CollectionRepository().query().forUser(Auth.getUser()).get(); if (items.Count < 1) { throw new ValidationException("You cannot create files without existing collection."); } foreach (var i in items) { collectionsDropdown.AddItem(i.Name); } var index = -1; if (!item.isNull()) { index = items.FindIndex(i => i.Name == (item.Collection?.Name ?? "")); } else if (item.isNull() && items.Count > 0) { index = 0; } collectionsDropdown.selectedIndex = index; }