Hi Everybody,
I've got a Big issue, trying to modify the ItemSource for a ComboBox
I create an ACCESS 2007 Database named SNIGDoFFE.accdb, my solution is named Data, I added the Database through theAdd New Source Configuration wizard
and I drap and drop the Field "Libelle" from the Table Ethnie to the the ComboBox, so it modify my files like This
In MainWindow.xaml.vb
PrivateSub Window_Loaded(sender AsObject, e As RoutedEventArgs)HandlesMyBase.LoadedDim SNIGDoFFEDataSet As Data.SNIGDoFFEDataSet =CType(Me.FindResource("SNIGDoFFEDataSet"), Data.SNIGDoFFEDataSet)'Load data into the table Ethnie. You can modify this code as needed.Dim SNIGDoFFEDataSetEthnieTableAdapter As Data.SNIGDoFFEDataSetTableAdapters.EthnieTableAdapter =New Data.SNIGDoFFEDataSetTableAdapter.EthnieTableAdapter() SNIGDoFFEDataSetEthnieTableAdapter.Fill(SNIGDoFFEDataSet.Ethnie)Dim EthnieViewSource As System.Windows.Data.CollectionViewSource =CType(Me.FindResource("EthnieViewSource"), System.Windows.Data.CollectionViewSource)'EthnieViewSource.View.MoveCurrentToFirst'I comment this line to leave the combobox emptyEndSub
The code for cboTest_SelectionChanged is this : (from http://social.msdn.microsoft.com/Forums/vstudio/en-US/05d0cf4d-b0cf-4c2c-8e00-c3993b759fec/wpf-combobox-lostfocus-not-working-as-expected-what-do-to?forum=wpf)
PrivateSub cboTesT_SelectionChanged(sender AsObject, e As SelectionChangedEventArgs)Handles cboTesT.SelectionChanged MessageBox.Show(CType(cboTesT.SelectedItem, ComboBoxItem).Content)EndSub
in XAML
<ComboBoxx:Name="cboTest"width="120"Margin"184,10,183,134"SelectionChanged="cboTest_SelectionChanged"DisplayMemberPath="Libelle"ItemSource="{Binding Source={StaticResource EthnieViewSource}}"/>
so in my Resources, it added this
<Window.Resources><local:SNIGDoFFEDataSetx:Key"SNIGDoFFEDataSet"/><CollectionViewSourcex:Key="EthnieViewSource"Source="{Binding Ethnie, Source={StaticResources SNIGDoFFEDataSet}}"/></Window.Resources>
The Solution is Built Correctly, the main Window loaded correctly, but when I select an item in the combobox, the program crashes, I try to remove all binding and create Item with <comboBoxItem> and everything work,but by binding the source from my database, it Crashes again.
Please help me, I don't got any Idea of the cause of this.