-1

I've got this code that populates a ListBox when a flyout is opened:

private void flyoutOpenPhotosets_Opened(object sender, object e)
{
    lstbxPhotosets.ItemsSource = PhotraxSQLiteUtils.GetPhotosets();
    foreach (String pset in App.CurrentlyMappedPhotosets)
    {
        int lstbxIndex = lstbxPhotosets.Items.IndexOf(pset);
        if (lstbxIndex >= 0)
        {
            lstbxPhotosets.Items[lstbxIndex].? what now?
        }
    }
}

GetPhotosets returns a List. That part works (the list box is populated with the appropriate string values)

The problem is with the rest of the code (the foreach block).

CurrentlyMappedPhotosets is also a List. I want matching members among the strings in CurrentlyMappedPhotosets and those in the ListBox to cause the item in the ListBox to be selected when the flyout displays.

I was hoping to do be able to do something like this:

lstbxPhotosets.Items[lstbxIndex].Selected = true;

...but lstbxPhotosets is disallowing that.

So how can I programmatically select specified ListBox items?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

1

Use

lstbxPhotosets.SelectedIndex = lstbxIndex
chue x
  • 18,573
  • 7
  • 56
  • 70
Addeladde
  • 777
  • 2
  • 9
  • 28