Home > Net >  Trying to display data in a DisplayActionSheet
Trying to display data in a DisplayActionSheet

Time:01-04

I have a collectionview pulling all the data from a class Terms in a contentpage. I have a SelectionChanged event handler that will pull up all the courses that make up the selected term.


    private async void termsCollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if(e.CurrentSelection != null)
        {
            Terms terms = (Terms)e.CurrentSelection.FirstOrDefault();
            await Navigation.PushAsync(new TermView(terms));
        }
    }

Then I have for Edit Term


    private async void EditTerm_Clicked(object sender, EventArgs e)
    {

    }

Basically I need 2 different selections inside of one page. 1 for the courses that make up a term and 1 for editing all the information for that term. Just throwing this piece out there in case somebody has a better way of doing it.

I stumbled across this method

await DisplayActionSheet()

I was wondering if there was a way to display a list of all the Terms I currently have to choose from. Once a term is selected, pass the termId through the EditTerms(termId) to view all the info for that selected term. All the videos I have seen are passing in strings to select.

I wouldn't mind writing out the terms are strings to select but Terms is scalable that can grow or shrink over time. So manual strings isn't really plausible.

EDIT - I have a method in my Database class (using sqlite) to get terms but I'm not able to figure out the syntax for accessing it.

        public static async Task <IEnumerable<Terms>> GetTerms()
        {
            await Init();

            var terms = await _db.Table<Terms>().ToListAsync();
            return terms;
        }

CodePudding user response:

if this is your list of terms

var terms = await _db.Table<Terms>().ToListAsync();

you can build an array using something like this (assuming that Term has a Name property, adjust accordingly)

var termarray = terms.Select(t => t.Name).ToArray();
   
  • Related