ijoyai 2013年10月24日
关于Datagrid编辑取消重新绑定数据的问题?请教各位,先谢谢了
silverlight4 + sql2008 +.net2010
movieDataGrid(DataGrid)和movieGrid(Grid)中的几个textbox间建立了双向绑定,当textbox中的数据修改后想取消修改,对movieDataGrid做了重新绑定数据,但未刷新为原始数据,求教正确的做法。

以下是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLA20131023.Web;
using System.Windows.Data;
using System.ServiceModel.DomainServices.Client;

namespace SLA20131023
{
public partial class MainPage : UserControl
{
private movieDomainContext movieCtx = new movieDomainContext();
private LoadOperation<Movie> loadop;

public MainPage()
{
InitializeComponent();
loadop = this.movieCtx.Load(movieCtx.GetMovieQuery());
loadop.Completed += new EventHandler(loadop_Completed);


}

void loadop_Completed(object sender, EventArgs e)
{
PagedCollectionView pager = new PagedCollectionView(loadop.Entities);
pager.PageSize = 5;
movieDataGrid.ItemsSource = pager;
movieDataPager.Source = pager;


}

private void movieDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
movieGrid.DataContext = movieDataGrid.SelectedItem;
}

private void btnCancel_Click(object sender, RoutedEventArgs e) //取消操作
{
movieDataGrid.ItemsSource = null;
movieDataGrid.ItemsSource = movieCtx.Movies;
movieGrid.DataContext = null;
movieGrid.DataContext = movieDataGrid.SelectedItem;
}

}
}

界面在此:
...全文
168 点赞 收藏 12
写回复
12 条回复

还没有回复,快来抢沙发~

发动态
发帖子
WPF/Silverlight
创建于2007-09-28

8160

社区成员

1.1w+

社区内容

WPF/Silverlight相关讨论
社区公告
暂无公告