This is a migrated thread and some comments may be shown as answers.

RadGridView with QueryableEntityCollectionView and EF6 How to get change notificatuionbs of the database

1 Answer 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Veteran
Michael asked on 08 Nov 2017, 06:10 PM

Radgridview ist filled with data from database. CRUD works fine.

The RadGridview doesn`t show any changes made outside in the database.

Adding Mode=TwoWay cause readonly error of the QueryableEntityCollectionView data binding

<UserControl x:Class="ERP.AdminModule.Views.AdminMainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <telerik:RadButton Content="Save" Command="{Binding Path=SubmitCommand}" CommandParameter="SubmitOrder" Margin="207,86,10,113.2"/>

        <telerik:RadGridView Name="customersGrid" GroupRenderMode="Flat"
                             Grid.Row="1"
                             Margin="0, 5, 0, 0"
                             AutoGenerateColumns="False"
                             ItemsSource="{Binding RolesView, Mode=TwoWay}"
                             IsReadOnly="False"
                             RowIndicatorVisibility="Collapsed"
                             CanUserFreezeColumns="False"
                             CanUserResizeColumns="False"
                             >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="RoleID"
                                            DataMemberBinding="{Binding RoleID}" />
                <telerik:GridViewDataColumn Header="Name"
                                            DataMemberBinding="{Binding Name}" />
                <telerik:GridViewDataColumn Header="Prio"
                                            DataMemberBinding="{Binding Prio}" />
            </telerik:RadGridView.Columns>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="RowEditEnded" >
                    <i:InvokeCommandAction Command="{Binding Path=SubmitCommand}" CommandParameter="SubmitOrder" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </telerik:RadGridView>

    </Grid>
</UserControl>

 

using System;
using System.Collections.ObjectModel;
using System.Linq;
using Prism.Events;
using ERP.DAL;
using Prism.Mvvm;
using Telerik.Windows.Data;
using System.Windows.Input;
using Prism.Commands;
using System.Threading.Tasks;

namespace ERP.AdminModule.ViewModels
{
    class AdminMainViewModel: BindableBase
    {
        public QueryableEntityCollectionView<ACL_Roles> rolesView;
        private readonly myERPContext ctx;

        public ICommand SubmitCommand { get; private set; }

        public AdminMainViewModel(IEventAggregator eventAggregator) : base()
        {
            try
            {
                this.ctx = new myERPContext();
                this.rolesView = new QueryableEntityCollectionView<ACL_Roles>((ctx as System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext, "ACL_Roles");

                this.SubmitCommand = new DelegateCommand<object>(this.OnSubmit, this.CanSubmit);
            }
            catch
            {

            }

        }

        private void OnSubmit(object arg) { ctx.SaveChanges(); }
        private bool CanSubmit(object arg) { return true; }
        
        public QueryableEntityCollectionView<ACL_Roles> RolesView
        {
            get { return this.rolesView; }
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 13 Nov 2017, 11:22 AM
Hi Michael,

Thank you for the code provided.

In order to achieve this with the given setup, you need to call the SaveChanges method of the ObjectContext. Can you please give it a try?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Veteran
Answers by
Stefan
Telerik team
Share this question
or