ListBox multiple items selection

4235
3
05-08-2015 12:50 PM
JoannaLaroussi
New Contributor

I have two-step query: query 1 selects all routes for given school and displays route numbers in a ListBox. Query 2 allows for selecting
one of routes from a ListBox. I am wondering how to select more than one route from a ListBox.

So here is my ListBox:

<StackPanel Orientation="Horizontal"
HorizontalAlignment
="Left" >

                            <TextBlock Text="Routes:" Width="100" TextAlignment="Left" Margin="5,5,-2,5"/>

                            <ListBox x:Name="RoutesFound" Width="50" Margin="5" SelectionChanged="selectedRoute_SelectionChanged" SelectionMode="Extended" />

                        </StackPanel>

private void selectedRoute_SelectionChanged(object sender, EventArgs e)

        {

            if (RoutesFound.SelectedIndex != -1)

            {

                _strSelectedRoute = RoutesFound.SelectedValue.ToString();  

            }

     _listSelectedRoutes.Add(_strSelectedRoute);

        }

where I added SelectionMode ="Extended" with a hope that it will allow me for multiple selection, but this did not happen.

I also tried to use SelectionMode ="Multiple", but without luck.

Does anybody can suggest how to select multiple items from aListBox and capture them in a list?

Tags (2)
0 Kudos
3 Replies
Asgharkhan
Occasional Contributor

in xml

<listbox1.item "schools/>

code behind

ListBox listBox1 = new ListBox();

listBox1.Items.Add("schools");

0 Kudos
JoannaLaroussi
New Contributor

Thank you for your response, but I do not see it how this can help me.

I would like to capture selected items from XAML, and I do not need to add more items in C#.

Right now this line

_strSelectedRoute = RoutesFound.SelectedValue.ToString();

captures a single selection, but I need to be able to capture multiple selection.

0 Kudos
DominiqueBroux
Esri Frequent Contributor

You can use the SelectedItems property which returns the list of selected items.

0 Kudos