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?
in xml
<listbox1.item "schools/>
code behind
ListBox listBox1 = new ListBox();
listBox1.Items.Add("schools");
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.
You can use the SelectedItems property which returns the list of selected items.