AutoSuggestBox ItemsSource from SQLite database

MikeBealeMikeBeale Member ✭✭

I've got stuck with this, and am very new to Xamatin Forms.

I'm wanting to use the dotMorten.Xamarin.Forms.AutoSuggestBox in my Xamarin Forms app.

I have the list of values in a SQLite table:
`public class Streets

{

    [PrimaryKey]

    [MaxLength(255)]

    public String StreetName { get; set; }

}`

I'm wanting to use this table as the ItemsSource for the AutoSuggestBox.

Using the ToDo example app I have the following code to get the records from the table:
`public Task<List> LookupStreetsAsync(String query)

    {

        return lookups.Table<Streets>().Where(s => s.StreetName.StartsWith(query)).OrderBy(s => s.StreetName).ToListAsync();

    }`

But I cannot get this to be the ItemsSource for my AutoSuggestBox:
`private void StreetAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs e)

    {

        if (e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)

        {

            String query = sender.Text.Trim();

            // only auto suggest if 3 or more characters

            if (query.Length > 2)

            {

                sender.ItemsSource = App.Lookups.LookupStreetsAsync(query);

            }

        }

    }`

The error is:
Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Collections.Generic.List<XamarinFirst.Streets>>' to 'System.Collections.IList'. An explicit conversion exists (are you missing a cast?)

I have Googled trying to cast from List to IList but nothing works, just get more errors!

How can I use my SQLite table with the AutoSuggestBox?

Thanks,
Mike

Sign In or Register to comment.