Setting selected item on Listbox in Silverlight - Windows Phone 7
Posted
by
Fishcake
on Stack Overflow
See other posts from Stack Overflow
or by Fishcake
Published on 2010-11-24T09:19:50Z
Indexed on
2010/12/22
10:54 UTC
Read the original article
Hit count: 223
I have a databound Listbox bound to a generic list as follows (Provider is a very simple class that just includes a single property (Name).
ProviderList = new List<Provider>();
//Populate list
Providers.ItemsSource = ProviderList;
I can save the selected item with no problem but I can't manage to set the selected item from code afterwards. I am trying to do so as follows:
int x = Providers.Items.IndexOf((Provider)_Settings["provider"]);
However IndexOf()
is always returning -1. If I inspect both Providers.Items[1] and _Setting["provider"] at runtime using the immediate window they both return
{StoreRetrieveData.Provider}
Name: "Greenflag"
Am I doing something wrong (well clearly I am)?
© Stack Overflow or respective owner