I have a listbox populated with 3 items from an SQLCE database using Linq.
For some reason when I select the item located at index 1, it highlights in the listbox but does not fire the selection change. If I select any other item (index 0 or 2) then the selection fires fine.
Any ideas?
I have checked the item in the database and I can’t see anything wrong with it.
EDIT: Requested Code
Xaml
<ListBox x:Name="lbxPlans" Grid.Row="5" Grid.ColumnSpan="2" Margin="12" ItemsSource="{Binding}" ItemTemplate="{DynamicResource PlanTemplate}" SelectionChanged="lbxPlans_SelectionChanged">
<DataTemplate x:Key="PlanTemplate">
<Grid Margin="0,3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Run No." VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="{Binding RunNumber}" VerticalAlignment="Top" Grid.Column="1" Margin="6,0"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Week Day:" VerticalAlignment="Top" Grid.Column="2"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="{Binding DayOfWeek}" VerticalAlignment="Top" Grid.Column="3" Margin="6,0"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Week Number:" VerticalAlignment="Top" Grid.Column="4"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="{Binding WeekNumber}" VerticalAlignment="Top" Grid.Column="5" Margin="6,0"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Desc:" VerticalAlignment="Top" Grid.Column="6"/>
<TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="{Binding Description}" VerticalAlignment="Top" Grid.Column="7" Margin="6,0"/>
</Grid>
</DataTemplate>
And
private void GetProgrammes()
{
var pro = from p in Globals.Instance.Database.Programme
select p;
lbxPlans.DataContext = null;
lbxPlans.DataContext = pro;
}
private void lbxPlans_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// TODO: Add event handler implementation here.
if (lbxPlans.SelectedIndex != 1)
{
MessageBox.Show("Selection Changed!");
}
}
EDIT 2: As Requested rather than creating pro from database items and assigning it to the Listbox DataContext I created them manually to eliminate database issues and still the problem is present. I then just ran an experiment by creating a List<string> with 3 values and assigned that to the listbox. The issue is still there! so is this now an issue with the Listbox itself?
lbxPlans.SelectedIndex != 1
You did not trace this in the debugger?