更改有界实体时更新datagrid [英] update datagrid when bounded entity is changed

查看:51
本文介绍了更改有界实体时更新datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据网格存在问题,无法反映其ItemSource中的更改.类似的问题似乎很常见,但我还没有找到解决方案.我有两个窗口,父窗口和子窗口,并且子窗口在窗口中添加了行".到桌子"绑定到数据网格 在父窗口中(我正在使用连接到ms sql数据库的实体框架).但是,无论我如何尝试,新行都不会显示在datagrid中.我以为那会自动...我已经搜寻尝试找出实体框架 正在实现INotifyPropertyChanged,但尚未能够找到.我还定义了一个事件来触发子窗口,父窗口来处理,并在事件处理程序中执行了datagrid.items.refresh()和datagrid.invalidatevisual();但 没有运气...(事件消失了,事件处理程序中的行已执行,但看不到结果)

I'm having problems with my datagrid not reflecting changes in its ItemSource. Similar problems seem to be common but I haven't found a solution. I have two windows, parent and child and the child window adds a "row" to a "table" which is bound to a datagrid in the parent window  (I'm using entity framework which is connected to a ms sql database). However no matter how I try the new row won't show in the datagrid. I thought that would automatic... I have searched to try and find out if the entity framework is implementing the INotifyPropertyChanged but havent been able to find out. I also defined an event for the child window to fire and for the parent to handle and in the eventhandler I did datagrid.items.refresh() followed by datagrid.invalidatevisual(); but no luck... (the event goes of and the lines in the eventhandler is executed but no visible result)

我在这里缺少基本的东西吗?

I'm a missing something fundamental here?

推荐答案

我以前没有使用过实体框架,但是如果它是数据库,我会以为如果添加了新行,需要回到数据库并获取最新的数据集.因此,可能值得您重新查询数据库(或使用实体框架进行查询)以 获取最新的数据集.

I've not used entity framework before but if it was a db I would have thought that if a new row is added you need to go back to the db and get the latest set of data. So it might worth you requerying the db (or however you do it using entity framework)to get the latest set of data.

 

这对我来说似乎是很多工作.您是否可以将新行传递到父窗口,然后让父窗口将其添加到datagrid集合中?这样,您还将在数据网格中显示 行,然后将其提交给 实体框架.

this sounds like a lot of work to me. Is it possible for you to pass the new row to the parent window and let the parent window add it to the datagrid collection? That way you will also have the  row appear in your datagrid and then commit it to the entity framework.

 

有意义的希望.


这篇关于更改有界实体时更新datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆