Sweta Sinha

Sweta Sinha

  • NA
  • 51
  • 42.2k

Add items to the listbox in Windows Phone application

Mar 3 2015 5:37 AM
Hi,
I have a listbox in xaml.I have to fetch a list of string from database and then have to display them in the listbox.The count of the items can be maximum 30,000.
I am fetching the data but when I am adding it in the listbox it crashes giving "Out of Memory Exception".
My Code:-
List<string> lstOfVals = Globals.dbHandler.getFullCache(s);
Dispatcher.BeginInvoke(() =>
{
 listbox.Items.Clear();
 foreach (string str in lstOfVals)
 {
   TextPhoneControl tpc = new TextPhoneControl ();
 tpc.shorthandValue.Text = str;
   listbox.Items.Add(tpc);
 }
});
 

Answers (6)