1. quanlich's Avatar
    Hi,

    I'm currently writing a dictionary app using databound app template. My database is a sqlite database with more than 300.000 rows. Here is my code to store loaded database.

    Code:
     public class Word
        {
            [PrimaryKey]
            public int Id { get; set; }
            
            public string WordString { get; set; }
    
            public string Content { get; set; }
        }
    
     public class WordList
        {
            public ObservableCollection<Word> Items { get; set; }
    
            public WordList()
            {
                Items = new ObservableCollection<Word>();
            }
        }
    
    public class ViewModel {
    
    //....
           public async void LoadData()
            {
                var query =  DB.Table<Word>();
                
                var result = await query.ToListAsync();
                
    
                foreach (Word w in result)
                {
                    WList.Items.Add( new Word()
                    {
                        Id = w.Id,
                        WordString = w.WordString,
                        Content = w.Content
                    });
                }
    
                IsDataLoaded = true;
            }
    
    }
    And I use a TextBlock to display wordString and a phoneTextBox to search words.

    Code:
     <toolkit:PhoneTextBox Hint="Search"
                                      TextChanged="SearchBox_TextChanged"
                                      Name="SearchBox"
                                      VerticalAlignment="Top" />
    
    .....
    <TextBlock Text="{Binding WordString}"
                                           FontSize="30"
                                           TextWrapping="Wrap"
                                           VerticalAlignment="Center"
                                           Margin="20,0,0,0"
                                           Foreground="Black"
                                           FontWeight="Bold"
                                           Grid.Row="0" />
    And here is the code for searching:

    Code:
    ....
     private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)        {
    IList<Word> results = App.ViewModel.WList.Items
                .Where(tb =>tb.WordString.StartWith(SearchBox.Text))
                .ToList();
    
        
         ListBox1.ItemsSource = results;}
    The problem is when I do a search, it takes to long to response.
    Could you please give me a hint to accelerate my search? Could I create an indexer on ObservableCollection?

    Thanks in advance.
    03-02-2014 12:35 PM
  2. Catholic Tech Geek's Avatar
    Instead of using StartsWiith(),you could try using the overloaded IndexOf(string, startindex, count) for String. This is just an idea.

    example: exstring.IndexOf(SearchBox.Text, 0, SearchBox.Text.Length);
    03-02-2014 11:56 PM
  3. quanlich's Avatar
    Thank Catholic but it doesn't help much. It even made the app crash.

    I tried to change observableCollection to other collections like Dictionary, List, HashShet... but I don't know why they do not display data on ListBox? Only ObservableCollection which functions!!
    03-03-2014 01:11 AM

Similar Threads

  1. Hotmail / outlook.com not syncing with phone / PC Outlook
    By Ed Bradburn in forum Windows Phone 8
    Replies: 13
    Last Post: 08-04-2016, 04:42 AM
  2. Surface 2 Crackling Sound with Amazon Instant Video
    By angusdegraosta in forum Microsoft Surface 2
    Replies: 33
    Last Post: 12-29-2015, 10:39 PM
  3. What earphones are you using with the Ativ?
    By Loco5150 in forum Samsung ATIV S
    Replies: 20
    Last Post: 05-12-2014, 01:17 AM
  4. Replies: 6
    Last Post: 04-08-2014, 12:05 AM
  5. Any improvement with the camera after update
    By maverick786us in forum Nokia Lumia 1520
    Replies: 6
    Last Post: 03-02-2014, 01:18 PM
LINK TO POST COPIED TO CLIPBOARD