Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Searchbar in Listview

BorisopritBorisoprit Member ✭✭✭

Fill a Listview from a Firebase database.
So far so good.

Want to use a Searchbar to filter the listview.

But when i enter something it is going blanc and that is it.

What am i missing ?

 public partial class MainPage : ContentPage
    {
        FirebaseHelper firebaseHelper = new FirebaseHelper();


        List<Adresclub> list = new List<Adresclub>();


        public MainPage()
        {
            InitializeComponent();
            Ladenview();
        }
        async public void Ladenview()
        {

            var allAdresclub = await firebaseHelper.GetAllAdresclub();
           lstBal.ItemsSource = allAdresclub;

        }

        private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
        {

            lstBal.BeginRefresh();

            if (string.IsNullOrWhiteSpace(e.NewTextValue))
                lstBal.ItemsSource = list;
            else
                lstBal.ItemsSource = list.Where(i => i.Tegenstander.Contains(e.NewTextValue));

            lstBal.EndRefresh();

        }
    }
}

Tagged:

Best Answer

Answers

  • Adeel984Adeel984 Member ✭✭✭

    Try this code

    if (string.IsNullOrWhiteSpace(e.NewTextValue)){
     lstBal.ItemsSource = null;
     lstBal.ItemsSource = list;
    }
    else {
    lstBal.ItemsSource = null;
    lstBal.ItemsSource = list.Where(i => i.Tegenstander.Contains(e.NewTextValue));
    }
    
  • BorisopritBorisoprit Member ✭✭✭

    Thanks for the reply Adeel984 ,

    But still empty listview after typing

    Also tryed another item from the database but also no luck.

  • BorisopritBorisoprit Member ✭✭✭

    Is it even possible to use this with items from a Firebase database ?

    The examples i find on the internet are all with a list and not from a database.

  • BorisopritBorisoprit Member ✭✭✭

    Thanks jezh,

    Got it working now .

    In the first try i used "Tegenstander" from the database but there are some "_" in the data , that is not working.

    On normal data from the database without the _ working great.

    Is there a way to get this fixed that i can filter with a _ in the word ?

  • jezhjezh Member, Xamarin Team Xamurai

    In the first try i used "Tegenstander" from the database but there are some "_" in the data , that is not working.

    Where is the _ located?

    If "_" is in the starting position, the results should be unaffected when we use the following code:

      lstBal.ItemsSource = list.Where(i => i.Tegenstander.Contains(e.NewTextValue));
    
  • BorisopritBorisoprit Member ✭✭✭

    the _ is not in starting position.

    Example , VV_HV , VVV_DV or even Lepelstr_Bo.

    Different posistions , and the most of the data is without the _ .

  • BorisopritBorisoprit Member ✭✭✭

    That are name's of soccer teams , because i cannot use space in the name to store in the database i used _

  • jezhjezh Member, Xamarin Team Xamurai

    When you enter the keywords, don't you want to enter the symbol _ ?

    If yes, you can try the following code:

     lstView.ItemsSource = veggies.Where(x => x.Name.Replace("_"," ").Contains(e.NewTextValue));
    
  • jezhjezh Member, Xamarin Team Xamurai

    Hi @Borisoprit , have you resolved your question?

  • BorisopritBorisoprit Member ✭✭✭

    jezh ,

    Tryed the code but still nothing , there comes an error .

    System.NullReferenceException
    Message=Object reference not set to an instance of an object.
    
    

    When using this code and use some other data without the _ everything is oke.

    Still problems with the _

  • jezhjezh Member, Xamarin Team Xamurai

    If it is convenient for you, could you please post a basic demo or some code snippets so that we can test on our side?

  • jezhjezh Member, Xamarin Team Xamurai
    edited September 15

    Hi @Borisopritm , have you resolved your question?

    If my reply is useful for you, could you please mark it an answered? Thanks in advance. :)

  • BorisopritBorisoprit Member ✭✭✭

    jehz , i cannot get it to work with the _ in the name's

    For now i use the search on city and that works.

    Thanks

Sign In or Register to comment.