locked
How to save selected Index to storage and load it to secondpage?

    Question

  • I bind an items to a listbox and i want the selectedindex will save to isolatedStorage and load the settings to SecondPage when navigated,

    here's my code im MainPagexaml.cs;

    if(display.SelectedIndex == 1)

    {

           Frame.navigate(Typeof(SecondPage));

    }

    ......................................................................

    // i want that the selectedIndex load from storage In my secondpage.xaml.cs;

    if(display2.SelectedIndex == //how to load the selectedindex from isolatedsettings here)

    Friday, January 09, 2015 7:14 AM

Answers

  • Hi icce cage,

    Try to select item when the UI is ready for instance you can set it when page loaded, the exception looks like the listbox is not ready without any items inside.

    protected void PageLoaded(object sender)
            {
                string u = e.Parameter.ToString();
    
                int y = Convert.ToInt32(u);
                display1.SelectedIndex = y;
            }

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 28, 2015 7:29 AM
    Moderator

All replies

  • why not use the navigationParameter? so:

     Frame.navigate(Typeof(SecondPage), display.SelectedIndex);

    or use application settings:

    ApplicationData.Current.LocalSettings.Values["SelectedIndex"] = display.SelectedIdnex


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, January 09, 2015 7:41 AM
  • I used parameter but still no luck;

    here's my code SecondPage.xaml.cs

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                string u = e.Parameter.ToString();

                int y = Convert.ToInt32(u);
                display1.SelectedIndex = y;
            }

            private void Page_Loaded(object sender, RoutedEventArgs e)
            {

                string u = e.Parameter.ToString();

                int y = Convert.ToInt32(u);
                display1.SelectedIndex = y;
            }

    Friday, January 09, 2015 10:43 AM
  • this one should work:

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                string u = e.Parameter.ToString();
    
                int y = Convert.ToInt32(u);
                display1.SelectedIndex = y;
            }
    only are you sure the list is already filled with items?


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Friday, January 09, 2015 12:03 PM
  • yes i bind the same items but in different layout...

    i want that the item clicked from MainPage must be  the first item to be loaded in the secondPage..


    • Edited by icce cage Friday, January 09, 2015 10:52 PM
    Friday, January 09, 2015 10:29 PM
  • Hi icce cage,

    Try to select item when the UI is ready for instance you can set it when page loaded, the exception looks like the listbox is not ready without any items inside.

    protected void PageLoaded(object sender)
            {
                string u = e.Parameter.ToString();
    
                int y = Convert.ToInt32(u);
                display1.SelectedIndex = y;
            }

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 28, 2015 7:29 AM
    Moderator