Hello all.
I have updated my Entity Framework 4.0 to 4.1Since i have a problem with the binding to Radgridview control.
My Dataclasses as sample:
In my UC i have into the Loaded-Event:
The Collectionview Method:
In my context class:
My save method:
In xaml of the radgridview:
It shows all cars, but when i save a new car, the list doesn´t refresh.
When i reload the UC, then all cars (the new one too) are all there.
Can you please help?
Reinhard
I have updated my Entity Framework 4.0 to 4.1Since i have a problem with the binding to Radgridview control.
My Dataclasses as sample:
namespace KfzOrtung6DataClasses.Modells{ public class Fahrzeuge { public Fahrzeuge() { this.FahrzeugPositionen = new ObservableCollection<Positionen>(); } [Required] [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public Guid ID { get; set; } [Required] [MaxLength(50)] public string Name { get; set; } [Required] [MaxLength(50)] public string Kennzeichen { get; set; } public string Rufnummer { get; set; } public int Aktiv { get; set; } public DateTime Ablaufsimkarte { get; set; } [MaxLength(4000)] public string Bemerkung { get; set; } public virtual ObservableCollection<Positionen> FahrzeugPositionen { get; private set; } }}In my UC i have into the Loaded-Event:
this.DataContext = this.ItemsSource;The Collectionview Method:
ICollectionView _itemsSource;public ICollectionView ItemsSource{ get { if (_itemsSource == null) { using (var ktt = new KfzContext6()) { ktt.MFahrzeuge.Load(); var c = ktt.MFahrzeuge.Local.ToBindingList(); var collectionViewSource = new CollectionViewSource {Source = c}; _itemsSource = collectionViewSource.View; } } return _itemsSource; } set { _itemsSource = value; OnPropertyChanged("ItemsSource"); }}#endregionIn my context class:
namespace KfzOrtung6DataClasses.Modells{ public class KfzContext6 : DbContext { public KfzContext6(): base("KfzContext6") { } public DbSet<Fahrzeuge> MFahrzeuge { get; set; } public DbSet<Positionen> MPositionen { get; set; } public DbSet<Tarife> MTarife { get; set; } public DbSet<Benutzer> MBenutzer { get; set; } public DbSet<SmsProtokoll> MSmsProtokoll { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // Hier können manuelle Änderungen an Datenbank vorgenommen werden!! //Beispiel: //modelBuilder.Entity<Benutzer>().Property(r => r.ID).HasColumnName("Id"); } }}My save method:
selectedFahrzeugAusListe.Aktiv = chkFahrzeugAktiv.IsChecked == true ? 1 : 0;selectedFahrzeugAusListe.Rufnummer = txFahrzeugGpsnummer.Text.Trim();selectedFahrzeugAusListe.Kennzeichen = txFahrzeugKennzeichen.Text.Trim();selectedFahrzeugAusListe.Bemerkung = txFahrzeugKommentar.Text.Trim();selectedFahrzeugAusListe.Name = txFahrzeugName.Text.Trim();selectedFahrzeugAusListe.Ablaufsimkarte = dateTimePicker.DisplayDate;using (var ktt = new KfzContext6()){ ktt.MFahrzeuge.Add(selectedFahrzeugAusListe); ktt.SaveChanges(); ItemsSource.Refresh();}In xaml of the radgridview:
<telerik:RadGridView AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" Margin="10,6,10,13" x:Name="FahrzeugGrid" RowIndicatorVisibility="Visible" AutoExpandGroups="True" IsFilteringAllowed="False" ShowGroupPanel="False" ShowGroupFooters="False" IsReadOnly="True" SelectionChanged="FahrzeugGrid_SelectionChanged" ActionOnLostFocus="None" AreRowDetailsFrozen="True" CanUserInsertRows="False" CanUserDeleteRows="False" RowDetailsVisibilityMode="Visible" Grid.Row="1" ItemsSource="{Binding ItemsSource, ElementName=DataSourceChangeNotificationsFahrzeugControl}" DataLoaded="FahrzeugGrid_DataLoaded" > <telerik:RadGridView.ParentRow> <telerik:GridViewRow IsTabStop="False" /> </telerik:RadGridView.ParentRow> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Fahrzeugname" Width="200" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Kennzeichen}" Header="Kennzeichen" Width="140" /> <telerik:GridViewColumn Header="Aktiv" Width="40" IsFilterable="True"> <telerik:GridViewColumn.CellTemplate> <DataTemplate> <CheckBox IsEnabled="False" IsChecked="{Binding Path=Aktiv, Converter={StaticResource CopnvertIntToBool1} }"> </CheckBox> </DataTemplate> </telerik:GridViewColumn.CellTemplate> </telerik:GridViewColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding Rufnummer}" Header="GPS Nummer" Width="150" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Ablaufsimkarte}" Header="Ablauf Karte" Width="90" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding Bemerkung}" Header="Kommentar" Width="*" /> </telerik:RadGridView.Columns></telerik:RadGridView>It shows all cars, but when i save a new car, the list doesn´t refresh.
When i reload the UC, then all cars (the new one too) are all there.
Can you please help?
Reinhard