How after updating data from one of the UI (at network) reload data at other UIs and keep relationship?

StackOverflow https://stackoverflow.com/questions/22314062

سؤال

When I add Entity data model for a MySql database to WPF application and CollectionViewSource created for both Parent and child tables like:

    <CollectionViewSource x:Key="topicmainViewSource" d:DesignSource="{d:DesignInstance {x:Type dbMRCPe:topicmain}, CreateList=True}"/>
    <CollectionViewSource x:Key="articlesRelatedViewSource" Source="{Binding topicsublev1, Source={StaticResource topicmainViewSource}}"/>

and create a DataContext to a grid and binding to radgridviews like

<Grid Name="maingrid" DataContext="{StaticResource topicmainViewSource}">

    <telerik:RadGridView x:Name="TopicMaingridview"  DataMember="idTopicMain" ItemsSource="{Binding}" />
    <telerik:RadGridView x:Name="articlesRelatedRadGridView" ItemsSource="{Binding Source={StaticResource articlesRelatedViewSource}}" />
 </Grid>

and this is the code to load data at cs

dbMRCPe.dbmrcpnephrologyEntities ctx = new dbMRCPe.dbmrcpnephrologyEntities();
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        ctx = new dbMRCPe.dbmrcpnephrologyEntities();

        System.Windows.Data.CollectionViewSource topicmainViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("topicmainViewSource")));
        // Load data by setting the CollectionViewSource.Source property:
        topicmainViewSource.Source = ctx.topicmains;
    }

The Question : if a user add data to gridview at runtime , how to reload data to other user interfaces at runtime if a refersh button used without loos relation ship between two grids?

هل كانت مفيدة؟

المحلول

Thanks ever one a solved it just after i but the question

by add new referance to datacontext like

private void reloadbtn_Click(object sender, RoutedEventArgs e)
    {
     dbMRCPe.dbmrcpnephrologyEntities ctx2 = new dbMRCPe.dbmrcpnephrologyEntities();
     ctx = ctx2;
     topicmainViewSource.Source = ctx.topicmains;

    }

if I use topicmainViewSource.Source = ctx.topicmains; directly it will not load the new data also I want to use ctx.SaveChanges() allover the code

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top