【问题标题】:How after updating data from one of the UI (at network) reload data at other UIs and keep relationship?从其中一个 UI(在网络上)更新数据后如何在其他 UI 上重新加载数据并保持关系?
【发布时间】:2014-03-11 00:24:00
【问题描述】:

当我将 MySql 数据库的实体数据模型添加到 WPF 应用程序和为父表和子表创建的 CollectionViewSource 时,例如:

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

并为网格创建 DataContext 并绑定到 radgridviews 之类的

<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>

这是在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;
    }

问题:如果用户在运行时将数据添加到gridview,如果使用的引用按钮没有在两个网格之间失去关系,如何在运行时将数据重新加载到其他用户界面?

【问题讨论】:

    标签: c# mysql wpf gridview entity-framework-5


    【解决方案1】:

    感谢有人在我之后解决了这个问题

    通过添加对数据上下文的新引用,例如

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

    如果我使用 topicmainViewSource.Source = ctx.topicmains;直接不会加载新数据 我也想在整个代码中使用 ctx.SaveChanges()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      相关资源
      最近更新 更多